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

Ignore symlinks that point to nonexistent targets #669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

egibs
Copy link
Member

@egibs egibs commented Nov 27, 2024

We attempt to evaluate symlinks when recursively scanning for files in a given scan path; however, this tends to pollute output when the symlinks point to targets that don't exist.

For example, -compat packages are essentially a collection of symlinks but the target is not installed as part of the package:

/ # apk add opentofu-1.8-compat
(1/1) Installing opentofu-1.8-compat (1.8.6-r0)
OK: 790 MiB in 50 packages
...
/ # ls -hal /usr/local/bin/ | grep tofu
lrwxrwxrwx    1 root     root          17 Nov 27 14:03 opentofu -> /usr/bin/opentofu
/ # ls /usr/bin/opentofu
ls: /usr/bin/opentofu: No such file or directory

Scanning this file fails:

/workspace # go run cmd/mal/mal.go analyze /usr/local/bin/opentofu
🔎 Scanning "/usr/local/bin/opentofu"
💣 find: eval "/usr/local/bin/opentofu": lstat /usr/bin/opentofu: no such file or directory
exit status 2

Instead, this PR returns gracefully when this is the case and logs the error instead:

/workspace # go run cmd/mal/mal.go analyze /usr/local/bin/opentofu
🔎 Scanning "/usr/local/bin/opentofu"
...
/workspace # go run cmd/mal/mal.go --verbose analyze /usr/local/bin/opentofu
🔎 Scanning "/usr/local/bin/opentofu"
time=2024-11-27T14:06:28.289Z level=INFO source=/workspace/pkg/action/scan.go:49 msg="symlink target does not exist: lstat /usr/bin/opentofu: no such file or directory"

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.

1 participant