2019-10-23 12:11:44 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-05-09 07:53:05 -07:00
|
|
|
set -exu -o pipefail
|
2019-10-23 12:11:44 -07:00
|
|
|
|
2020-05-13 13:07:26 -07:00
|
|
|
for d in src/fuzzing/*/ ; do
|
|
|
|
fuzz_cases+="$(basename "$d"), "
|
|
|
|
done
|
|
|
|
|
|
|
|
FUZZ_OPTIONS_STRING="Options are: ${fuzz_cases::-2}"
|
2020-04-30 17:49:52 -07:00
|
|
|
|
|
|
|
required_options_count=0
|
|
|
|
|
|
|
|
function help {
|
|
|
|
cat <<EOF
|
|
|
|
Start fuzzing a case in a previously zcashd built for AFL.
|
2020-05-13 13:07:26 -07:00
|
|
|
This script must be run from within the top level directory of a zcash clone.
|
2020-04-30 17:49:52 -07:00
|
|
|
Additional arguments are passed-through to AFL.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
$0 --afl-install=AFL_INSTALL_DIR --fuzz-case=FUZZ_CASE [ ARGUMENTS... ]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-f, --fuzz-case $FUZZ_OPTIONS_STRING
|
|
|
|
-h, --help Print this help message
|
|
|
|
-i, --afl-install Directory where AFL is installed
|
|
|
|
EXAMPLE:
|
|
|
|
./zcutil/afl/afl-run.sh -i /tmp/afl -f DecodeHexTx
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while (( "$#" )); do
|
|
|
|
case "$1" in
|
|
|
|
-f|--fuzz-case)
|
|
|
|
FUZZ_CASE=$2
|
|
|
|
((++required_options_count))
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-i|--afl-install)
|
|
|
|
AFL_INSTALL_DIR=$2
|
|
|
|
((++required_options_count))
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-*|--*=)
|
|
|
|
echo "Error: Unsupported flag $1" >&2
|
|
|
|
help
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if ((required_options_count < 2)); then
|
|
|
|
help
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-23 12:11:44 -07:00
|
|
|
|
2019-10-28 17:28:54 -07:00
|
|
|
"$AFL_INSTALL_DIR/afl-fuzz" -i "./src/fuzzing/$FUZZ_CASE/input" -o "./src/fuzzing/$FUZZ_CASE/output" "$@" ./src/zcashd @@
|