Skip to content

Commit 25985ce

Browse files
author
Maceo Thompson
committed
internal/scan: disallow package input in mod level
Throws an error when the user attempts to input a package path when running govulncheck with -scan=module. Change-Id: I97c6dd32c027a42e1bd4b3edd8e1bea90b447888 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/544595 Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 008d020 commit 25985ce

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

cmd/govulncheck/testdata/testfiles/failures/source_fail.ct

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ There are errors with the provided package patterns:
2828
-: package foo is not in GOROOT (/tmp/foo)
2929

3030
For details on package patterns, see https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns.
31+
32+
#####
33+
# Test of handing a package pattern to scan level module
34+
$ govulncheck -scan module -C ${moddir}/vuln pattern --> FAIL 2
35+
patterns are not accepted for module only scanning

internal/scan/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func validateConfig(cfg *config) error {
107107
if len(cfg.patterns) == 1 && isFile(cfg.patterns[0]) {
108108
return fmt.Errorf("%q is a file.\n\n%v", cfg.patterns[0], errNoBinaryFlag)
109109
}
110+
if cfg.ScanLevel == govulncheck.ScanLevelModule && len(cfg.patterns) != 0 {
111+
return fmt.Errorf("patterns are not accepted for module only scanning")
112+
}
110113
case modeBinary:
111114
if cfg.test {
112115
return fmt.Errorf("the -test flag is not supported in binary mode")

0 commit comments

Comments
 (0)