Skip to content

Commit

Permalink
internal/scan: change the way convert mode works
Browse files Browse the repository at this point in the history
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 <iancottrell@google.com>
Reviewed-by: Maceo Thompson <maceothompson@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Auto-Submit: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
ianthehat authored and gopherbot committed Aug 16, 2023
1 parent e3a5c49 commit 3eb86d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/govulncheck/testdata/convert_text.ct
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#####
# Test using the conversion from json on stdin to text on stdout
$ govulncheck -mode=convert < convert_input.json
$ govulncheck -mode=convert < convert_input.json --> FAIL 3
Scanning your code and P packages across M dependent modules for known vulnerabilities...

Vulnerability #1: GO-2021-0265
Expand Down
16 changes: 2 additions & 14 deletions internal/scan/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ func RunGovulncheck(ctx context.Context, env []string, r io.Reader, stdout io.Wr
if err := parseFlags(cfg, stderr, args); err != nil {
return err
}
if cfg.mode == modeConvert {
return convertJSONToText(r, stdout)
}

client, err := client.NewClient(cfg.db, nil)
if err != nil {
Expand Down Expand Up @@ -60,6 +57,8 @@ func RunGovulncheck(ctx context.Context, env []string, r io.Reader, stdout io.Wr
err = runBinary(ctx, handler, cfg, client)
case modeQuery:
err = runQuery(ctx, handler, cfg, client)
case modeConvert:
err = govulncheck.HandleJSON(r, handler)
}
if err != nil {
return err
Expand Down Expand Up @@ -132,14 +131,3 @@ func scannerVersion(cfg *config, bi *debug.BuildInfo) {
}
cfg.ScannerVersion = buf.String()
}

// convertJSONToText converts r, which is expected to be the JSON output of govulncheck,
// into the text output, and writes the output to w.
func convertJSONToText(r io.Reader, w io.Writer) error {
h := NewTextHandler(w)
if err := govulncheck.HandleJSON(r, h); err != nil {
return err
}
Flush(h)
return nil
}

0 comments on commit 3eb86d4

Please sign in to comment.