-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -dict option (like AFL's -x) to replace low-signal string literal list #315
base: master
Are you sure you want to change the base?
Changes from all commits
1b70c6d
f01a8e4
5d957e6
2e5342a
f8cbffe
1911501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that it really matters, but let's not convert to string and then convert back to []byte. Use bytes.Split instead. Or use a bufio.Scanner, which'll be simpler yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
for S := range splits { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be shorter with |
||
token := splits[S] | ||
if token == "\n" || token == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it contain "\n" is we split by "\n"? |
||
continue // skip blanks | ||
} | ||
ro.strLits = append(ro.strLits, []byte(token)) | ||
} | ||
} | ||
hub.ro.Store(ro) | ||
|
||
go hub.loop() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment explaining why we stat here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we pass *flagDict to workerMain? Or read here and pass contents to workerMain? |
||
if err != nil { | ||
log.Fatalf("cannot read dictionary file %q: %v", *flagDict, err) | ||
} | ||
if dictStat.Size() == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to allow an empty dictionary? E.g. I can imagine someone using this to disable dictionaries. (Maybe it'd break something in the mutator code? If so, we could add an early exit when strLits is empty.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel if the user is manually specifying a dictionary, it would be strange if it was empty -- therefore probably a mistake. Happy to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, we could log. |
||
log.Fatalf("dictionary file %q is empty", *flagDict) | ||
} | ||
} | ||
|
||
go func() { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGINT) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This renaming looks excessive, especially if we remove the log.Printf. Just use *flagDict.