mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 02:26:42 +01:00
Survive indexing dead symlinks (#2645)
* 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>
This commit is contained in:
parent
a909e3cec9
commit
65cadda486
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -0,0 +1 @@
|
||||
../somewhere/self/fd
|
||||
Loading…
x
Reference in New Issue
Block a user