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

Conversation

deitch
Copy link
Contributor

@deitch deitch commented Jun 5, 2023

Fixes #1860

Ensures that if a symlink in a directory points to something that does not exist, it logs a debug message and continues, rather than adding a new root which does not exist, which would cause a fatal error.

Signed-off-by: Avi Deitcher <avi@deitcher.net>
Comment on lines +373 to +378
// 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 = ""
}
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.

Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

I think this is good as it is 👍

@kzantow kzantow merged commit 1764e1c into anchore:main Jun 5, 2023
@deitch deitch deleted the handle-outside-symlinks branch June 6, 2023 07:20
GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
Signed-off-by: Avi Deitcher <avi@deitcher.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

symlinks within a scanned directory tree are parsed outside the tree, failing if target does not exist
2 participants