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

Only consider that are in a PATH dir from generateCmdProviders #1164

Merged
merged 1 commit into from
May 3, 2024
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
14 changes: 12 additions & 2 deletions pkg/sca/sca.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ func allowedPrefix(path string, prefixes []string) bool {
return false
}

var cmdPrefixes = []string{"bin/", "sbin/", "usr/bin/", "usr/sbin/"}
func isInDir(path string, dirs []string) bool {
mydir := filepath.Dir(path)
for _, d := range dirs {
if mydir == d || mydir+"/" == d {
return true
}
}
return false
}

var pathBinDirs = []string{"bin/", "sbin/", "usr/bin/", "usr/sbin/"}

func generateCmdProviders(ctx context.Context, hdl SCAHandle, generated *config.Dependencies) error {
log := clog.FromContext(ctx)
Expand Down Expand Up @@ -116,7 +126,7 @@ func generateCmdProviders(ctx context.Context, hdl SCAHandle, generated *config.
}

if mode.Perm()&0555 == 0555 {
if allowedPrefix(path, cmdPrefixes) {
if isInDir(path, pathBinDirs) {
basename := filepath.Base(path)
log.Infof(" found command %s", path)
generated.Provides = append(generated.Provides, fmt.Sprintf("cmd:%s=%s", basename, hdl.Version()))
Expand Down
Loading