Skip to content

Commit 6362db7

Browse files
committed
refactor: Update fuzz scripts
Use cargo-fuzz instead of hongfuzz. Make the scripts more readable.
1 parent 9d05999 commit 6362db7

File tree

3 files changed

+9
-46
lines changed

3 files changed

+9
-46
lines changed

fuzz/cycle.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# Continuosly cycle over fuzz targets running each for 1 hour.
44
# It uses chrt SCHED_IDLE so that other process takes priority.
5-
#
6-
# For hfuzz options see https://github.com/google/honggfuzz/blob/master/docs/USAGE.md
75

8-
set -e
6+
set -o errexit # exit immediately if any command fails
7+
set -o xtrace # print trace of executed commands
8+
99
REPO_DIR=$(git rev-parse --show-toplevel)
1010
# shellcheck source=./fuzz-util.sh
1111
source "$REPO_DIR/fuzz/fuzz-util.sh"
@@ -14,12 +14,11 @@ while :
1414
do
1515
for targetFile in $(listTargetFiles); do
1616
targetName=$(targetFileToName "$targetFile")
17-
echo "Fuzzing target $targetName ($targetFile)"
1817

1918
# fuzz for one hour
20-
HFUZZ_RUN_ARGS='--run_time 3600' chrt -i 0 cargo hfuzz run "$targetName"
19+
chrt -i 0 cargo-fuzz run "$targetName" -- -max_total_time=3600
2120
# minimize the corpus
22-
HFUZZ_RUN_ARGS="-i hfuzz_workspace/$targetName/input/ -P -M" chrt -i 0 cargo hfuzz run "$targetName"
21+
cargo-fuzz cmin "$targetName"
2322
done
2423
done
2524

fuzz/fuzz-util.sh

-28
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ targetFileToName() {
1515
| sed 's/\//_/g'
1616
}
1717

18-
targetFileToHFuzzInputArg() {
19-
baseName=$(basename "$1")
20-
dirName="${baseName%.*}"
21-
if [ -d "hfuzz_input/$dirName" ]; then
22-
echo "HFUZZ_INPUT_ARGS=\"-f hfuzz_input/$FILE/input\""
23-
fi
24-
}
25-
2618
listTargetNames() {
2719
for target in $(listTargetFiles); do
2820
targetFileToName "$target"
@@ -37,23 +29,3 @@ checkWindowsFiles() {
3729
exit 2
3830
fi
3931
}
40-
41-
# Checks whether a fuzz case output some report, and dumps it in hex
42-
getReport() {
43-
reportFile="hfuzz_workspace/$1/HONGGFUZZ.REPORT.TXT"
44-
if [ -f "$reportFile" ]; then
45-
cat "$reportFile"
46-
for CASE in "hfuzz_workspace/$1/SIG"*; do
47-
xxd -p -c10000 < "$CASE"
48-
done
49-
return 1
50-
fi
51-
return 0
52-
}
53-
54-
# Check for reports and exit if there are any
55-
checkReport() {
56-
if ! getReport "$1"; then
57-
exit 1
58-
fi
59-
}

fuzz/fuzz.sh

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
set -ex
2+
set -o errexit # exit immediately if any command fails
3+
set -o xtrace # print trace of executed commands
34

45
REPO_DIR=$(git rev-parse --show-toplevel)
56

@@ -18,17 +19,8 @@ fi
1819
cargo --version
1920
rustc --version
2021

21-
# Testing
22-
cargo install --force honggfuzz --no-default-features
22+
# Run fuzz target
2323
for targetFile in $targetFiles; do
2424
targetName=$(targetFileToName "$targetFile")
25-
echo "Fuzzing target $targetName ($targetFile)"
26-
if [ -d "hfuzz_input/$targetName" ]; then
27-
HFUZZ_INPUT_ARGS="-f hfuzz_input/$targetName/input\""
28-
else
29-
HFUZZ_INPUT_ARGS=""
30-
fi
31-
HFUZZ_RUN_ARGS="--run_time 30 --exit_upon_crash -v $HFUZZ_INPUT_ARGS" cargo hfuzz run "$targetName"
32-
33-
checkReport "$targetName"
25+
cargo-fuzz run "$targetName" -- -max_total_time=30
3426
done

0 commit comments

Comments
 (0)