Skip to content

Commit

Permalink
filter unrelated fixed versions
Browse files Browse the repository at this point in the history
Signed-off-by: tomersein <tomersein@gmail.com>
  • Loading branch information
tomersein committed Nov 20, 2024
1 parent 9a5228e commit 7e2e2fd
Showing 1 changed file with 28 additions and 0 deletions.
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

0 comments on commit 7e2e2fd

Please sign in to comment.