-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (67 loc) · 1.7 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"go/ast"
"os"
)
func main() {
// Parse command line args
args := parseArgs()
// Find the Fuzz function in the package
pkg, fname, fuzzFunc := findFuzzFunc(args[0], *funcName)
if fuzzFunc == nil {
fmt.Printf("Fuzz function %s not found in package %s\n", *funcName, args[0])
os.Exit(1)
}
err := os.Chdir(args[0])
if err != nil {
panic(err)
}
params := fuzzFunc.Type.Params.List
if len(params) != 1 { // TODO: Support multiple parameters
fmt.Printf("Fuzz function %s must only have one parameter\n", fname)
os.Exit(1)
}
build(pkg.Name, fname, fuzzFunc)
if *runFuzzer {
run(pkg.Name, fname, fuzzFunc, args[1:])
}
}
func build(pkgName, fname string, fuzzFunc *ast.FuncDecl) {
if *all || *native {
fmt.Println("Generating Go native fuzzing test ...")
generateGoNative(pkgName, fname, fuzzFunc)
}
if *all || *libfuzzer {
fmt.Println("\nBuilding libFuzzer binary ...")
buildLibfFuzzer(pkgName, fname, fuzzFunc)
}
if *all || *gofuzz {
if pkgName == `main` {
fmt.Println("\nPackage main not supported by go-fuzz")
} else {
fmt.Println("\nBuilding go-fuzz binary ...")
buildGoFuzz(pkgName, fname, fuzzFunc)
}
}
if *all || *afl {
fmt.Println("\nBuilding AFL++ binary ...")
buildAFL(pkgName, fname, fuzzFunc)
}
}
func run(pkgName, fname string, fuzzFunc *ast.FuncDecl, args []string) {
switch {
case *native:
fmt.Println("\nRunning Go native fuzzing test ...")
runGoNative(pkgName, fname, fuzzFunc, args)
case *libfuzzer:
fmt.Println("\nRunning libFuzzer ...")
runLibFuzzer(args)
case *gofuzz && pkgName != `main`:
fmt.Println("\nRunning go-fuzz ...")
runGoFuzz(args)
case *afl:
fmt.Println("\nRunning AFL++ ...")
runAFL(args)
}
}