Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in directory indexer, handle outside symlinks #1861

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions syft/internal/fileresolver/directory_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Comment on lines +373 to +378
Copy link
Contributor

@kzantow kzantow Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking how this is used, what if this was moved above, to line 337 and behaved similar to when os.ReadLink fails? e.g.:

	if _, err := os.Stat(targetAbsPath); err != nil && errors.Is(err, os.ErrNotExist) {
		return "", fmt.Errorf("link %s points to unresolved path %s", p, targetAbsPath)
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. In that case, it would return an error, when that isn't actually what we want. A symlink might be invalid now, but the file could appear later. Think of a link to a mount in a container, or to a log file that will be created later.

The symlink itself not existing, or being unreadable, is an error; the target not existing is a hanging symlink, which is fine.


return targetAbsPath, nil
}

Expand Down