Skip to content

Commit

Permalink
internal/vulncheck: explicitly exclude devel from affected ranges
Browse files Browse the repository at this point in the history
For now, "(devel)" should never be matched.

Change-Id: Ia6b001caef1a1faf093b6757f3fb89d27e160bb2
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/598715
Reviewed-by: Maceo Thompson <maceothompson@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
zpavlinovic committed Jul 18, 2024
1 parent 201ff88 commit 079fa4d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions internal/vulncheck/vulncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,10 @@ func affectingVulnerabilities(vulns []*ModVulns, os, arch string) affectingVulns
if a.Module.Path != module.Path {
continue
}

// A module version is affected if
// - it is included in one of the affected version ranges
// - and module version is not ""
if modVersion == "" {
// Module version of "" means the module version is not available,
// and so we don't want to spam users with potential false alarms.
continue
}
if !semver.Affects(a.Ranges, modVersion) {
if !affected(modVersion, a) {
continue
}

var filteredImports []osv.Package
for _, p := range a.EcosystemSpecific.Packages {
if matchesPlatform(os, arch, p) {
Expand Down Expand Up @@ -196,6 +188,21 @@ func affectingVulnerabilities(vulns []*ModVulns, os, arch string) affectingVulns
return filtered
}

// affected checks if modVersion is affected by a:
// - it is included in one of the affected version ranges
// - and module version is not "" and "(devel)"
func affected(modVersion string, a osv.Affected) bool {
const devel = "(devel)"
if modVersion == "" || modVersion == devel {
// Module version of "" means the module version is not available
// and devel means it is in development stage. Either way, we don't
// know the exact version so we don't want to spam users with
// potential false alarms.
return false
}
return semver.Affects(a.Ranges, modVersion)
}

func matchesPlatform(os, arch string, e osv.Package) bool {
return matchesPlatformComponent(os, e.GOOS) &&
matchesPlatformComponent(arch, e.GOARCH)
Expand Down

0 comments on commit 079fa4d

Please sign in to comment.