Skip to content

Commit c13fda0

Browse files
committed
Fix usage output behavior, make README consistent with usage blurb
1 parent 5eec3af commit c13fda0

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Simple local log4j vulnerability scanner
23

34
(Written in Go because, you know, "write once, run anywhere.")
@@ -25,20 +26,20 @@ page.
2526
# Using the scanner
2627

2728
```
28-
$ ./local-log4j-vuln-scanner [--verbose] [--quiet] [--ignore-v1] \
29-
[--exclude /path/to/exclude …] [--log /path/to/file.log] \
29+
$ ./local-log4j-vuln-scanner [-verbose] [-quiet] [-ignore-v1] \
30+
[-exclude /path/to/exclude …] [-log /path/to/file.log] \
3031
/path/to/app1 /path/to/app2 …
3132
```
3233

33-
The `--verbose` flag will show every .jar and .war file checked, even if no problem is found.
34+
The `-verbose` flag will show every .jar and .war file checked, even if no problem is found.
3435

35-
The `--quiet` flag will supress output except for indicators of a known vulnerability.
36+
The `-quiet` flag will supress output except for indicators of a known vulnerability.
3637

37-
The `--ignore-v1` flag will _exclude_ checks for log4j 1.x vulnerabilities.
38+
The `-ignore-v1` flag will _exclude_ checks for log4j 1.x vulnerabilities.
3839

39-
The `--log` flag allows everythig to be written to a log file instead of stdout/stderr.
40+
The `-log` flag allows everythig to be written to a log file instead of stdout/stderr.
4041

41-
Use the `--exclude` flag to exclude subdirectories from being scanned. Can be used multiple times.
42+
Use the `-exclude` flag to exclude subdirectories from being scanned. Can be used multiple times.
4243

4344
If class files indicating one of the vulnerabilities are found,
4445
messages like the following are printed to standard output:

scanner/main.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ func main() {
108108
flag.StringVar(&logFileName, "log", "", "log file to write output to")
109109
flag.BoolVar(&quiet, "quiet", false, "no ouput unless vulnerable")
110110
flag.BoolVar(&ignoreV1, "ignore-v1", false, "ignore log4j 1.x versions")
111+
flag.Usage = func() {
112+
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
113+
flag.PrintDefaults()
114+
fmt.Fprint(flag.CommandLine.Output(), " PATH [, PATH ...]\n paths to search for Java code\n")
115+
}
111116
flag.Parse()
117+
args := flag.Args()
118+
if len(args) < 1 {
119+
flag.Usage()
120+
os.Exit(1)
121+
}
112122

113123
if !quiet {
114124
fmt.Printf("%s - a simple local log4j vulnerability scanner\n\n", filepath.Base(os.Args[0]))
115125
}
116126

117-
if len(os.Args) < 2 {
118-
fmt.Fprintf(os.Stderr, "Usage: %s [--verbose] [--quiet] [--ignore-v1] [--exclude <path>] [--log <file>] [ paths ... ]\n", os.Args[0])
119-
os.Exit(1)
120-
}
121-
122127
if logFileName != "" {
123128
f, err := os.Create(logFileName)
124129
if err != nil {
@@ -130,7 +135,7 @@ func main() {
130135
defer f.Close()
131136
}
132137

133-
for _, root := range flag.Args() {
138+
for _, root := range args {
134139
filepath.Walk(filepath.Clean(root), func(path string, info os.FileInfo, err error) error {
135140
if err != nil {
136141
fmt.Fprintf(errFile, "%s: %s\n", path, err)

0 commit comments

Comments
 (0)