Skip to content

Commit 65a3641

Browse files
author
Maceo Thompson
committed
internal/scan: change text based on scan level
This change modifies the text output of govulncheck depending on the scan level - specifically omitting assumptions about callstack information when govulncheck never ran callstack analysis. Change-Id: Id3ba3a1c97edb6140f0f00d58d9ae76737fc0ce1 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/545638 Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 7827b5d commit 65a3641

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Informational ===
22

3-
There is 1 vulnerability in modules that you require that is neither
4-
imported nor called. You may not need to take any action.
3+
There is 1 vulnerability in modules that you require. Use -scan=symbol
4+
with govulncheck for more fine grained vulnerability detection.
55
See https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck for details.
66

77
Vulnerability #1: GO-0000-0001
@@ -12,6 +12,5 @@ Vulnerability #1: GO-0000-0001
1212
Fixed in: golang.org/vmod@v0.1.3
1313
Platforms: amd
1414

15-
No vulnerabilities found.
1615

1716
Share feedback at https://go.dev/s/govulncheck-feedback.

internal/scan/testdata/multi-stack-modlevel.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
=== Informational ===
22

3-
There are 2 vulnerabilities in modules that you require that are
4-
neither imported nor called. You may not need to take any action.
3+
There are 2 vulnerabilities in modules that you require. Use
4+
-scan=symbol with govulncheck for more fine grained vulnerability
5+
detection.
56
See https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck for details.
67

78
Vulnerability #1: GO-0000-0002
@@ -19,6 +20,5 @@ Vulnerability #2: GO-0000-0001
1920
Fixed in: golang.org/vmod@v0.1.3
2021
Platforms: amd
2122

22-
No vulnerabilities found.
2323

2424
Share feedback at https://go.dev/s/govulncheck-feedback.

internal/scan/text.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,32 @@ func (h *TextHandler) byVulnerability(findings []*findingSummary) {
159159
if onlyImported > 0 {
160160
informational.WriteString("Found " + fmt.Sprint(onlyImported))
161161
informational.WriteString(choose(onlyImported == 1, ` vulnerability`, ` vulnerabilities`))
162-
informational.WriteString(" in packages that you import, but there are no call stacks leading to the use of ")
163-
informational.WriteString(choose(onlyImported == 1, `this vulnerability.`, `these vulnerabilities.`))
162+
informational.WriteString(" in packages that you import")
163+
if h.scanLevel.WantSymbols() {
164+
informational.WriteString(", but there are no call stacks leading to the use of ")
165+
informational.WriteString(choose(onlyImported == 1, `this vulnerability.`, `these vulnerabilities.`))
166+
} else {
167+
informational.WriteString(".")
168+
}
164169
}
165170
if onlyRequired > 0 {
166171
isare := choose(onlyRequired == 1, ` is `, ` are `)
167172
informational.WriteString(" There" + isare + choose(onlyImported > 0, `also `, ``) + fmt.Sprint(onlyRequired))
168173
informational.WriteString(choose(onlyRequired == 1, ` vulnerability `, ` vulnerabilities `))
169-
informational.WriteString("in modules that you require that" + isare)
170-
informational.WriteString("neither imported nor called.")
174+
informational.WriteString("in modules that you require")
175+
if h.scanLevel.WantSymbols() {
176+
informational.WriteString(" that" + choose(h.scanLevel.WantSymbols(), isare, " may be "))
177+
informational.WriteString("neither imported nor called.")
178+
} else {
179+
informational.WriteString(".")
180+
}
181+
182+
}
183+
if h.scanLevel.WantSymbols() {
184+
informational.WriteString(" You may not need to take any action.")
185+
} else {
186+
informational.WriteString(" Use -scan=symbol with govulncheck for more fine grained vulnerability detection.")
171187
}
172-
informational.WriteString(" You may not need to take any action.")
173188
h.wrap("", informational.String(), 70)
174189
h.print("\nSee https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck for details.\n\n")
175190
index := 0
@@ -283,7 +298,7 @@ func (h *TextHandler) traces(traces []*findingSummary) {
283298
func (h *TextHandler) summary(findings []*findingSummary) {
284299
counters := counters(findings)
285300
if counters.VulnerabilitiesCalled == 0 {
286-
h.print("No vulnerabilities found.\n")
301+
h.print(choose(h.scanLevel.WantSymbols(), "No vulnerabilities found.\n", ""))
287302
return
288303
}
289304
h.print(`Your code is affected by `)

0 commit comments

Comments
 (0)