Skip to content

Commit c154f6a

Browse files
committed
internal/scan: remove redundant new lines
An extra new line is added when either 1) there is no summary of "other" vulnerabilities found or 2) no suggestion. This CL removes those lines. Change-Id: Ic6ab8c3a4b8ab193fdcd88e4afe65ab42a9a1794 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/562055 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Maceo Thompson <maceothompson@google.com> Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 0b50c25 commit c154f6a

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

cmd/govulncheck/testdata/testfiles/binary-module/binary_module_text.ct

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ Vulnerability #4: GO-2020-0015
4444
Fixed in: golang.org/x/text@v0.3.3
4545

4646
Your code may be affected by 4 vulnerabilities.
47-
4847
Use '-scan symbol' for more fine grained vulnerability detection.

cmd/govulncheck/testdata/testfiles/source-module/source_module_text.ct

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Vulnerability #2: GO-2021-0113
2626
Fixed in: golang.org/x/text@v0.3.7
2727

2828
Your code may be affected by 2 vulnerabilities.
29-
3029
Use '-scan symbol' for more fine grained vulnerability detection.
3130

3231
#####
@@ -56,5 +55,4 @@ Vulnerability #2: GO-2021-0113
5655
Fixed in: golang.org/x/text@v0.3.7
5756

5857
Your code may be affected by 2 vulnerabilities.
59-
6058
Use '-scan symbol' for more fine grained vulnerability detection.

internal/scan/testdata/module-vuln.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ Vulnerability #1: GO-0000-0001
99
Platforms: amd
1010

1111
Your code may be affected by 1 vulnerability.
12-
1312
Use '-scan symbol' for more fine grained vulnerability detection.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ Vulnerability #2: GO-0000-0001
1616
Platforms: amd
1717

1818
Your code may be affected by 2 vulnerabilities.
19-
2019
Use '-scan symbol' for more fine grained vulnerability detection.

internal/scan/text.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func (h *TextHandler) traces(traces []*findingSummary) {
319319
}
320320

321321
func (h *TextHandler) summary(c summaryCounters) {
322+
// print short summary of findings identified at the desired level of scan precision
322323
var vulnCount int
323324
h.print("Your code ", choose(h.scanLevel.WantSymbols(), "is", "may be"), " affected by ")
324325
switch h.scanLevel {
@@ -346,6 +347,20 @@ func (h *TextHandler) summary(c summaryCounters) {
346347
}
347348
h.print(".\n")
348349

350+
// print summary for vulnerabilities found at other levels of scan precision
351+
if other := h.summaryOtherVulns(c); other != "" {
352+
h.wrap("", other, 80)
353+
h.print("\n")
354+
}
355+
356+
// print suggested flags for more/better info depending on scan level and if in verbose mode
357+
if sugg := h.summarySuggestion(); sugg != "" {
358+
h.wrap("", sugg, 80)
359+
h.print("\n")
360+
}
361+
}
362+
363+
func (h *TextHandler) summaryOtherVulns(c summaryCounters) string {
349364
var summary strings.Builder
350365
if c.VulnerabilitiesRequired+c.VulnerabilitiesImported == 0 {
351366
summary.WriteString("This scan found no other vulnerabilities in ")
@@ -367,26 +382,26 @@ func (h *TextHandler) summary(c summaryCounters) {
367382
summary.WriteString(choose(h.scanLevel.WantSymbols(), ", but your code doesn't appear to call these vulnerabilities.", "."))
368383
}
369384
}
370-
h.wrap("", summary.String(), 80)
371-
h.print("\n")
372-
// print suggested flags for more/better info depending on scan level and if in verbose mode
385+
return summary.String()
386+
}
387+
388+
func (h *TextHandler) summarySuggestion() string {
389+
var sugg strings.Builder
373390
switch h.scanLevel {
374391
case govulncheck.ScanLevelSymbol:
375392
if !h.showAllVulns {
376-
h.print("Use ", verboseMessage, ".")
393+
sugg.WriteString("Use " + verboseMessage + ".")
377394
}
378395
case govulncheck.ScanLevelPackage:
379-
var message strings.Builder
380-
message.WriteString("Use " + symbolMessage)
396+
sugg.WriteString("Use " + symbolMessage)
381397
if !h.showAllVulns {
382-
message.WriteString(" and " + verboseMessage)
398+
sugg.WriteString(" and " + verboseMessage)
383399
}
384-
message.WriteString(".")
385-
h.wrap("", message.String(), 80)
400+
sugg.WriteString(".")
386401
case govulncheck.ScanLevelModule:
387-
h.print("Use ", symbolMessage, ".")
402+
sugg.WriteString("Use " + symbolMessage + ".")
388403
}
389-
h.print("\n")
404+
return sugg.String()
390405
}
391406

392407
func (h *TextHandler) style(style style, values ...any) {

0 commit comments

Comments
 (0)