Skip to content

Commit

Permalink
Don't emit last_affected versions when there are fixed versions (#1691)
Browse files Browse the repository at this point in the history
At the end of version extraction, strip out any last_affected versions
when there are preferred fixed versions present, to avoid the mix of
fixed and last_affected versions ever being converted to commits and
potentially winding up in the PackageInfo/VersionInfo input to
combine-to-osv.
  • Loading branch information
andrewpollock authored Oct 3, 2023
1 parent b4cdcdf commit 7f669ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
12 changes: 12 additions & 0 deletions vulnfeeds/cves/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,18 @@ func ExtractVersionInfo(cve CVEItem, validVersions []string) (v VersionInfo, not
notes = append(notes, " - "+version)
}
}

// Remove any lastaffected versions in favour of fixed versions.
if v.HasFixedVersions() {
affectedVersionsWithoutLastAffected := []AffectedVersion{}
for _, av := range v.AffectedVersions {
if av.LastAffected != "" {
continue
}
affectedVersionsWithoutLastAffected = append(affectedVersionsWithoutLastAffected, av)
}
v.AffectedVersions = affectedVersionsWithoutLastAffected
}
return v, notes
}

Expand Down
21 changes: 3 additions & 18 deletions vulnfeeds/cves/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ func TestRepo(t *testing.T) {
expectedOk: true,
},
{
description: "Freedesktop GitLab commit URL observed in CVE-2022-46285",
inputLink: "https://gitlab.freedesktop.org/xorg/lib/libxpm/-/commit/a3a7c6dcc3b629d7650148",
description: "Freedesktop GitLab commit URL observed in CVE-2022-46285",
inputLink: "https://gitlab.freedesktop.org/xorg/lib/libxpm/-/commit/a3a7c6dcc3b629d7650148",
expectedRepoURL: "https://gitlab.freedesktop.org/xorg/lib/libxpm",
expectedOk: true,
expectedOk: true,
},
{
description: "Freedesktop cGit mirror",
Expand Down Expand Up @@ -737,21 +737,6 @@ func TestExtractVersionInfo(t *testing.T) {
Fixed: "2.8.1",
LastAffected: "",
},
{
Introduced: "",
Fixed: "",
LastAffected: "2.9.0-rc1",
},
{
Introduced: "",
Fixed: "",
LastAffected: "2.9.0-rc0",
},
{
Introduced: "",
Fixed: "",
LastAffected: "2.9.0-rc2",
},
},
},
expectedNotes: []string{},
Expand Down

0 comments on commit 7f669ba

Please sign in to comment.