Skip to content

Commit ebda8dc

Browse files
committed
cmd,internal/scan: remove verbose mode
It isn't clear that having a detailed callstack is useful outside of json mode, so remove the verbose text output for now. Change-Id: Ie8bfe3e1d343eb8a86370453be93b6a80dfdf113 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/481295 Run-TryBot: Julie Qiu <[email protected]> Reviewed-by: Julie Qiu <[email protected]> Reviewed-by: Tatiana Bradley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent a72173c commit ebda8dc

18 files changed

+19
-78
lines changed

cmd/govulncheck/testdata/informational.ct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$ govulncheck -dir ${moddir}/informational -v .
1+
$ govulncheck -dir ${moddir}/informational .
22
govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback.
33

44
Using go1.18 and [email protected] with

cmd/govulncheck/testdata/source.ct

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$ govulncheck -dir ${moddir}/vuln -v . --> FAIL 3
1+
$ govulncheck -dir ${moddir}/vuln . --> FAIL 3
22
govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback.
33

44
Using go1.18 and [email protected] with
@@ -20,10 +20,7 @@ Vulnerability #1: GO-2021-0113
2020
Fixed in: golang.org/x/[email protected]
2121

2222
Call stacks in your code:
23-
#1: for function Parse
24-
golang.org/vuln.main
25-
.../vuln.go:13:16
26-
golang.org/x/text/language.Parse
23+
.../vuln.go:13:16: golang.org/vuln.main calls golang.org/x/text/language.Parse
2724

2825
=== Informational ===
2926

cmd/govulncheck/testdata/stdlib.ct

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$ govulncheck -dir ${moddir}/stdlib -v . --> FAIL 3
1+
$ govulncheck -dir ${moddir}/stdlib . --> FAIL 3
22
govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback.
33

44
Using go1.18 and [email protected] with
@@ -19,7 +19,4 @@ Vulnerability #1: GO-2022-0969
1919
Fixed in: net/[email protected]
2020

2121
Call stacks in your code:
22-
#1: for function ListenAndServe
23-
golang.org/stdlib.main
24-
.../stdlib.go:17:31
25-
net/http.ListenAndServe
22+
.../stdlib.go:17:31: golang.org/stdlib.main calls net/http.ListenAndServe

cmd/govulncheck/testdata/usage.ct

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ usage:
1515
comma-separated list of build tags
1616
-test
1717
analyze test files. Only valid for source code.
18-
-v print a full call stack for each vulnerability
1918

2019
For details, see https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck.
2120

@@ -38,6 +37,5 @@ usage:
3837
comma-separated list of build tags
3938
-test
4039
analyze test files. Only valid for source code.
41-
-v print a full call stack for each vulnerability
4240

4341
For details, see https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck.

internal/govulncheck/result.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ import (
1212
"golang.org/x/vuln/internal/osv"
1313
)
1414

15-
// Mode indicates the display mode that the user specified for running
16-
// govulncheck.
17-
type Mode string
18-
19-
const (
20-
ModeCompact Mode = "Compact"
21-
ModeVerbose Mode = "Verbose"
22-
)
23-
2415
// AnalysisType indicates the type of analysis performed by govulncheck.
2516
type AnalysisType string
2617

@@ -57,10 +48,6 @@ type Config struct {
5748

5849
// Analysis is the analysis type.
5950
Analysis AnalysisType `json:"analysis,omitempty"`
60-
61-
// Mode controls the information that is printed to the user, either
62-
// compact or verbose.
63-
Mode Mode `json:"callstack_mode,omitempty"` // TODO: remove field and verbose mode
6451
}
6552

6653
type Progress struct {

internal/scan/flags.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type config struct {
2121
db string
2222
json bool
2323
dir string
24-
verbose bool
2524
tags []string
2625
test bool
2726
}
@@ -34,7 +33,6 @@ func (c *Cmd) parseFlags() (*config, error) {
3433
)
3534
flags := flag.NewFlagSet("", flag.ContinueOnError)
3635
flags.BoolVar(&cfg.json, "json", false, "output JSON")
37-
flags.BoolVar(&cfg.verbose, "v", false, "print a full call stack for each vulnerability")
3836
flags.BoolVar(&cfg.test, "test", false, "analyze test files. Only valid for source code.")
3937
flags.StringVar(&cfg.db, "db", "https://vuln.go.dev", "vulnerability database URL")
4038
flags.StringVar(&mode, "mode", "", "source or binary modes are supported, default is source")

internal/scan/run.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ func newConfig(ctx context.Context, cfg *config) *govulncheck.Config {
8282
config := govulncheck.Config{
8383
DataSource: cfg.db,
8484
Analysis: cfg.analysis,
85-
Mode: govulncheck.ModeCompact,
86-
}
87-
if cfg.verbose {
88-
config.Mode = govulncheck.ModeVerbose
8985
}
9086
if cfg.analysis == govulncheck.AnalysisSource {
9187
// The Go version is only relevant for source analysis, so omit it for

internal/scan/template.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package scan
66

77
import (
88
_ "embed"
9-
"fmt"
109
"sort"
1110
"strings"
1211

@@ -34,12 +33,12 @@ type tmplResult struct {
3433

3534
// createTmplResult transforms Result r into a
3635
// template structure for printing.
37-
func createTmplResult(vulns []*govulncheck.Vuln, verbose, source bool) tmplResult {
36+
func createTmplResult(vulns []*govulncheck.Vuln, source bool) tmplResult {
3837
// unaffected are (imported) OSVs, none of which vulnerabilities are called.
3938
var r tmplResult
4039
var vInfos []tmplVulnInfo
4140
for _, v := range vulns {
42-
vInfos = append(vInfos, createTmplVulnInfo(v, verbose, source))
41+
vInfos = append(vInfos, createTmplVulnInfo(v, source))
4342
}
4443
r.Affected, r.Unaffected = splitVulns(vInfos)
4544
r.AffectedModules = affectedModules(vInfos)
@@ -103,23 +102,19 @@ type tmplVulnInfo struct {
103102
// createTmplVulnInfo creates a template vuln info for
104103
// a vulnerability that is called by source code or
105104
// present in the binary.
106-
func createTmplVulnInfo(v *govulncheck.Vuln, verbose, source bool) tmplVulnInfo {
105+
func createTmplVulnInfo(v *govulncheck.Vuln, source bool) tmplVulnInfo {
107106
vInfo := tmplVulnInfo{
108107
ID: v.OSV.ID,
109108
Details: v.OSV.Details,
110109
Affected: !source || IsCalled(v),
111110
}
112111

113112
// stacks returns call stack info of p as a
114-
// string depending on verbose and source mode.
113+
// string depending on source mode.
115114
stacks := func(p *govulncheck.Package) string {
116115
if !source {
117116
return ""
118117
}
119-
120-
if verbose {
121-
return verboseCallStacks(p.CallStacks)
122-
}
123118
return defaultCallStacks(p.CallStacks)
124119
}
125120

@@ -208,23 +203,6 @@ func defaultCallStacks(css []govulncheck.CallStack) string {
208203
return b.String()
209204
}
210205

211-
func verboseCallStacks(css []govulncheck.CallStack) string {
212-
// Display one full call stack for each vuln.
213-
i := 1
214-
var b strings.Builder
215-
for _, cs := range css {
216-
b.WriteString(fmt.Sprintf("#%d: for function %s\n", i, cs.Symbol))
217-
for _, e := range cs.Frames {
218-
b.WriteString(fmt.Sprintf(" %s\n", FuncName(e)))
219-
if pos := AbsRelShorter(Pos(e)); pos != "" {
220-
b.WriteString(fmt.Sprintf(" %s\n", pos))
221-
}
222-
}
223-
i++
224-
}
225-
return b.String()
226-
}
227-
228206
// platforms returns a string describing the GOOS, GOARCH,
229207
// or GOOS/GOARCH pairs that the vuln affects for a particular
230208
// module mod. If it affects all of them, it returns the empty

internal/scan/testdata/binary.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Binary",
4-
"callstack_mode": "Compact"
3+
"analysis": "Binary"
54
}
65
}
76
{

internal/scan/testdata/multi_stacks.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/no_vulns.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/platform-all.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/platform-one-arch-only.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/platform-one-import.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/platform-two-imports.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/platform-two-os-only.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/testdata/source.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"config": {
3-
"analysis": "Source",
4-
"callstack_mode": "Compact"
3+
"analysis": "Source"
54
}
65
}
76
{

internal/scan/text.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func (h *textHandler) Flush() error {
6262
}
6363

6464
source := h.config.Analysis == govulncheck.AnalysisSource
65-
verbose := h.config.Mode == govulncheck.ModeVerbose
66-
tmplRes := createTmplResult(h.vulns, verbose, source)
65+
tmplRes := createTmplResult(h.vulns, source)
6766
h.vulns = nil
6867
tmpl, err := template.New("govulncheck").Funcs(funcMap).Parse(outputTemplate)
6968
if err != nil {

0 commit comments

Comments
 (0)