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

Filter unrelated fixed version #2271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmd/grype/cli/commands/explore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package commands
1 change: 1 addition & 0 deletions cmd/grype/cli/commands/explore_cve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package commands
28 changes: 28 additions & 0 deletions grype/search/cpe.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ func addNewMatch(matchesByFingerprint map[match.Fingerprint]match.Match, vuln vu
candidateMatch = existingMatch
}

// filter unrelated fixed versions in case fixed versions are larger than 1
if len(candidateMatch.Vulnerability.Fix.Versions) > 1 {
var filteredVersions []string
format := version.FormatFromPkg(p)
cons, err := version.GetConstraint(fmt.Sprintf("<=%s", candidateMatch.Package.Version), format)
if err != nil {
log.WithFields("package", p.Name).Trace("skipping filtering fixed versions")
}

for _, v := range candidateMatch.Vulnerability.Fix.Versions {
comparedVersion, err := version.NewVersion(v, format)
if err != nil {
log.WithFields("package", p.Name, "version", v).Trace("error while creating version in filtering fixed versions")
}
skip, err := cons.Satisfied(comparedVersion)
if err != nil {
log.WithFields("package", p.Name, "version", v).Trace("error while comparing version in filtering fixed versions")
continue
}
if skip {
continue
}
filteredVersions = append(filteredVersions, v)
}

candidateMatch.Vulnerability.Fix.Versions = filteredVersions
}

candidateMatch.Details = addMatchDetails(candidateMatch.Details,
match.Detail{
Type: match.CPEMatch,
Expand Down
Loading