Skip to content

Commit

Permalink
Survive indexing dead symlinks (anchore#2645)
Browse files Browse the repository at this point in the history
* survive indexing branches that start with a bad symlink

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add log statement

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
wagoodman authored Feb 14, 2024
1 parent b4d7ed4 commit 231ec13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions syft/internal/fileresolver/directory_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ func isRealPath(root string) (bool, error) {
func (r *directoryIndexer) indexBranch(root string, stager *progress.Stage) ([]string, error) {
rootRealPath, err := filepath.EvalSymlinks(root)
if err != nil {
var pathErr *os.PathError
if errors.As(err, &pathErr) {
// we can't index the path, but we shouldn't consider this to be fatal
// TODO: known-unknowns
log.WithFields("root", root, "error", err).Trace("unable to evaluate symlink while indexing branch")
return nil, nil
}
return nil, err
}

Expand Down
12 changes: 12 additions & 0 deletions syft/internal/fileresolver/directory_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ func TestDirectoryIndexer_index(t *testing.T) {
}
}

func TestDirectoryIndexer_index_survive_badSymlink(t *testing.T) {
// test-fixtures/bad-symlinks
// ├── root
// │ ├── place
// │ │ └── fd -> ../somewhere/self/fd
// │ └── somewhere
// ...
indexer := newDirectoryIndexer("test-fixtures/bad-symlinks/root/place/fd", "test-fixtures/bad-symlinks/root/place/fd")
_, _, err := indexer.build()
require.NoError(t, err)
}

func TestDirectoryIndexer_SkipsAlreadyVisitedLinkDestinations(t *testing.T) {
var observedPaths []string
pathObserver := func(_, p string, _ os.FileInfo, _ error) error {
Expand Down

0 comments on commit 231ec13

Please sign in to comment.