diff --git a/go-fuzz/hub.go b/go-fuzz/hub.go index cb55b00a9..6c4fed390 100644 --- a/go-fuzz/hub.go +++ b/go-fuzz/hub.go @@ -6,6 +6,8 @@ package main import ( "fmt" "log" + "io/ioutil" + "strings" "net/rpc" "path/filepath" "sync" @@ -116,6 +118,23 @@ func newHub(metadata MetaData) *Hub { ro.intLits = append(ro.intLits, []byte(lit.Val)) } } + if *flagDict != "" { + ro.strLits = nil // Discard existing tokens + fileName := *flagDict + dictData, err := ioutil.ReadFile(fileName) + if err != nil { + log.Fatalf("could not read tokens from %q: %v", fileName, err) + } + textData := string(dictData) + splits := strings.Split(textData,"\n") + for S := range splits { + token := splits[S] + if token == "\n" || token == "" { + continue // skip blanks + } + ro.strLits = append(ro.strLits, []byte(token)) + } + } hub.ro.Store(ro) go hub.loop() diff --git a/go-fuzz/main.go b/go-fuzz/main.go index 123c253cd..40cea4a4d 100644 --- a/go-fuzz/main.go +++ b/go-fuzz/main.go @@ -42,6 +42,7 @@ var ( flagSonar = flag.Bool("sonar", true, "use sonar hints") flagV = flag.Int("v", 0, "verbosity level") flagHTTP = flag.String("http", "", "HTTP server listen address (coordinator mode only)") + flagDict = flag.String("dict", "", "dictionary file containing string tokens (one per line, not quoted)") shutdown uint32 shutdownC = make(chan struct{}) @@ -57,6 +58,16 @@ func main() { log.Fatalf("both -http and -worker are specified") } + if *flagDict != "" { + dictStat, err := os.Stat(*flagDict) + if err != nil { + log.Fatalf("cannot read dictionary file %q: %v", *flagDict, err) + } + if dictStat.Size() == 0 { + log.Fatalf("dictionary file %q is empty", *flagDict) + } + } + go func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGINT)