Skip to content

Commit 3eb86d4

Browse files
ianthehatgopherbot
authored andcommitted
internal/scan: change the way convert mode works
This changes convert mode to just modify the source of vulnerabilities This means it builds the output and handles exit codes like normal. This fixes the fact that convert does not obey -show flags, or return failure on vulnerabilities. Change-Id: Ia264d0acbfe49f2ff814be2305e108f144a17d73 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/517156 Run-TryBot: Ian Cottrell <[email protected]> Reviewed-by: Maceo Thompson <[email protected]> Reviewed-by: Zvonimir Pavlinovic <[email protected]> Auto-Submit: Ian Cottrell <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent e3a5c49 commit 3eb86d4

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

cmd/govulncheck/testdata/convert_text.ct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#####
22
# Test using the conversion from json on stdin to text on stdout
3-
$ govulncheck -mode=convert < convert_input.json
3+
$ govulncheck -mode=convert < convert_input.json --> FAIL 3
44
Scanning your code and P packages across M dependent modules for known vulnerabilities...
55

66
Vulnerability #1: GO-2021-0265

internal/scan/run.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ func RunGovulncheck(ctx context.Context, env []string, r io.Reader, stdout io.Wr
2727
if err := parseFlags(cfg, stderr, args); err != nil {
2828
return err
2929
}
30-
if cfg.mode == modeConvert {
31-
return convertJSONToText(r, stdout)
32-
}
3330

3431
client, err := client.NewClient(cfg.db, nil)
3532
if err != nil {
@@ -60,6 +57,8 @@ func RunGovulncheck(ctx context.Context, env []string, r io.Reader, stdout io.Wr
6057
err = runBinary(ctx, handler, cfg, client)
6158
case modeQuery:
6259
err = runQuery(ctx, handler, cfg, client)
60+
case modeConvert:
61+
err = govulncheck.HandleJSON(r, handler)
6362
}
6463
if err != nil {
6564
return err
@@ -132,14 +131,3 @@ func scannerVersion(cfg *config, bi *debug.BuildInfo) {
132131
}
133132
cfg.ScannerVersion = buf.String()
134133
}
135-
136-
// convertJSONToText converts r, which is expected to be the JSON output of govulncheck,
137-
// into the text output, and writes the output to w.
138-
func convertJSONToText(r io.Reader, w io.Writer) error {
139-
h := NewTextHandler(w)
140-
if err := govulncheck.HandleJSON(r, h); err != nil {
141-
return err
142-
}
143-
Flush(h)
144-
return nil
145-
}

0 commit comments

Comments
 (0)