fix: handle invalid symlinks (#1861)

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher 2023-06-05 22:04:14 +03:00 committed by GitHub
parent c560ffd811
commit 1764e1c3f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -370,6 +370,13 @@ func (r directoryIndexer) addSymlinkToIndex(p string, info os.FileInfo) (string,
metadata.LinkDestination = linkTarget
r.index.Add(*ref, metadata)
// if the target path does not exist, then do not report it as a new root, or try to send
// syft parsing there.
if _, err := os.Stat(targetAbsPath); err != nil && errors.Is(err, os.ErrNotExist) {
log.Debugf("link %s points to unresolved path %s, ignoring target as new root", p, targetAbsPath)
targetAbsPath = ""
}
return targetAbsPath, nil
}