Skip to content

Commit 207b5b9

Browse files
committed
internal/report: change behavior of guessVulnerableAt when no fix
The function guessVulnerableAt now returns an error if the given version ranges are invalid. This avoids unexpected behavior such as successfully returning the latest version of a module when there is no fix, but the introduced version isn't actually understood by the proxy. Change-Id: I742ef108f1902936c64aa8fdca1d3ed4847d640d Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/522296 Run-TryBot: Tatiana Bradley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 0daa69a commit 207b5b9

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

internal/genericosv/testdata/yaml/GHSA-54q4-74p3-mgcw.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ modules:
33
- module: github.com/zhaojh329/rttys
44
versions:
55
- introduced: 4.0.0
6-
vulnerable_at: 1.1.0
76
summary: rttys SQL Injection vulnerability
87
description: |-
98
SQL Injection vulnerability in rttys versions 4.0.0, 4.0.1, and 4.0.2 in api.go,
@@ -19,4 +18,3 @@ references:
1918
notes:
2019
- 'create: unsupported version range event models.Event{Introduced:"", Fixed:"", LastAffected:"4.0.2", Limit:""}'
2120
- 'lint: github.com/zhaojh329/rttys: bad version "4.0.0": github.com/zhaojh329/[email protected]: invalid version: should be v0 or v1, not v4'
22-
- 'lint: github.com/zhaojh329/rttys: vulnerable_at version 1.1.0 is not inside vulnerable range'

internal/genericosv/testdata/yaml/GHSA-7fxj-fr3v-r9gj.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ modules:
55
- module: github.com/pingcap/tidb
66
versions:
77
- introduced: 6.2.0
8-
vulnerable_at: 1.0.9
98
summary: TiDB vulnerable to Use of Externally-Controlled Format String
109
description: |-
1110
TiDB server (importer CLI tool) prior to version 6.4.0 & 6.1.3 is vulnerable to
@@ -26,4 +25,3 @@ notes:
2625
- 'create: unsupported version range event models.Event{Introduced:"", Fixed:"", LastAffected:"6.1.2", Limit:""}'
2726
- 'create: unsupported version range event models.Event{Introduced:"", Fixed:"", LastAffected:"6.4.0-alpha1", Limit:""}'
2827
- 'lint: github.com/pingcap/tidb: bad version "6.2.0": github.com/pingcap/[email protected]: invalid version: should be v0 or v1, not v6'
29-
- 'lint: github.com/pingcap/tidb: vulnerable_at version 1.0.9 is not inside vulnerable range'

internal/report/fix.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212
"strings"
1313

14+
"golang.org/x/vulndb/internal/osvutils"
1415
"golang.org/x/vulndb/internal/proxy"
1516
"golang.org/x/vulndb/internal/version"
1617
)
@@ -125,7 +126,16 @@ func (m *Module) guessVulnerableAt(pc proxyClient) (string, error) {
125126
if fixed == "" {
126127
latest, err := pc.Latest(m.Module)
127128
if err != nil || latest == "" {
128-
return "", fmt.Errorf("could not find latest version from proxy: %s", err)
129+
return "", fmt.Errorf("no fix, but could not find latest version from proxy: %s", err)
130+
}
131+
132+
// Make sure the latest version is actually in the vulnerable range.
133+
// This may not be the case if the proxy doesn't recognize the affected versions.
134+
affected, err := osvutils.AffectsSemver(AffectedRanges(m.Versions), latest)
135+
if err != nil {
136+
return "", err
137+
} else if !affected {
138+
return "", fmt.Errorf("no fix, but latest version %s is not inside vulnerable range", latest)
129139
}
130140

131141
return latest, nil

0 commit comments

Comments
 (0)