Setup some simple fuzz helpers for unmarshal.

This commit is contained in:
Andrew Chambers 2020-04-05 23:05:18 +12:00
parent 810ef7401c
commit 98b2fa4d64
3 changed files with 67 additions and 2 deletions

View File

@ -3,12 +3,26 @@
To use these, you need to install afl (of course), and xterm. A tiling window manager helps manage
many concurrent fuzzer instances.
Note, afl sometimes requires system configuration, if you find AFL quitting prematurely, try manually
launching it and addressing any error messages.
## Fuzz the parser
```
$ sh ./tools/afl/prepare_to_fuzz.sh
export NFUZZ=1
$ export NFUZZ=1
$ sh ./tools/afl/fuzz.sh parser
Ctrl+C when done to close all fuzzer terminals.
$ sh ./tools/afl/aggregate_cases.sh parser
$ ls ./fuzz_out/parser_aggregated/
```
```
## Fuzz the unmarshaller
```
$ janet ./tools/afl/generate_unmarshal_testcases.janet
$ sh ./tools/afl/prepare_to_fuzz.sh
$ export NFUZZ=1
$ sh ./tools/afl/fuzz.sh unmarshal
Ctrl+C when done to close all fuzzer terminals.
$ sh ./tools/afl/aggregate_cases.sh unmarshal
$ ls ./fuzz_out/unmarshal_aggregated/
```

View File

@ -0,0 +1,49 @@
(os/mkdir "./tools/afl/unmarshal_testcases/")
(defn spit-case [n v]
(spit
(string "./tools/afl/unmarshal_testcases/" (string n))
(marshal v make-image-dict)))
(def cases [
nil
"abc"
:def
'hij
123
(int/s64 123)
"7"
[1 2 3]
@[1 2 3]
{:a 123}
@{:b 'xyz}
(peg/compile
'{:a (* "a" :b "a")
:b (* "b" (+ :a 0) "b")
:main (* "(" :b ")")})
(fn f [a] (fn [] {:ab a}))
(fn f [a] (print "hello world!"))
(do
(defn f [a] (yield) @[1 "2"])
(def fb (fiber/new f))
(resume fb)
fb)
])
(eachk i cases
(spit-case i (in cases i)))

View File

@ -0,0 +1,2 @@
(pp (unmarshal (slurp ((dyn :args) 1)) load-image-dict))