From 0c4b0037ae0c4afa2dfaa088b47b80bcaf105b39 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Mon, 1 Aug 2022 11:07:54 +0600 Subject: [PATCH 1/2] skip symlinks and hardlinks from tar scan --- pkg/fanal/walker/tar.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/fanal/walker/tar.go b/pkg/fanal/walker/tar.go index 4875ce00a66f..9bb1573a49c8 100644 --- a/pkg/fanal/walker/tar.go +++ b/pkg/fanal/walker/tar.go @@ -3,6 +3,7 @@ package walker import ( "archive/tar" "bytes" + "fmt" "io" "io/fs" "os" @@ -45,6 +46,10 @@ func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string, filePath = strings.TrimLeft(filepath.Clean(filePath), "/") fileDir, fileName := filepath.Split(filePath) + if fileName == "packages.config" { + fmt.Println() + } + // e.g. etc/.wh..wh..opq if opq == fileName { opqDirs = append(opqDirs, fileDir) @@ -64,10 +69,11 @@ func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string, skipDirs = append(skipDirs, filePath) continue } - case tar.TypeSymlink, tar.TypeLink, tar.TypeReg: + case tar.TypeReg: if w.shouldSkipFile(filePath) { continue } + // symlinks and hardlinks have no content in reader, skip them default: continue } From bb666be33c89091db0f45788cdee0bd29c448111 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Mon, 1 Aug 2022 11:13:13 +0600 Subject: [PATCH 2/2] refactor --- pkg/fanal/walker/tar.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/fanal/walker/tar.go b/pkg/fanal/walker/tar.go index 9bb1573a49c8..836c22fc562c 100644 --- a/pkg/fanal/walker/tar.go +++ b/pkg/fanal/walker/tar.go @@ -3,7 +3,6 @@ package walker import ( "archive/tar" "bytes" - "fmt" "io" "io/fs" "os" @@ -46,10 +45,6 @@ func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string, filePath = strings.TrimLeft(filepath.Clean(filePath), "/") fileDir, fileName := filepath.Split(filePath) - if fileName == "packages.config" { - fmt.Println() - } - // e.g. etc/.wh..wh..opq if opq == fileName { opqDirs = append(opqDirs, fileDir)