forked from solana-labs/solana-program-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzz.sh
executable file
·50 lines (42 loc) · 1.4 KB
/
fuzz.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
source ./ci/rust-version.sh stable
cargo +"$rust_stable" install honggfuzz --version=0.5.55 --force || true
usage() {
exitcode=0
if [[ -n "$1" ]]; then
exitcode=1
echo "Error: $*"
fi
echo "Usage: $0 [fuzz-target] [run-time-in-seconds]"
exit $exitcode
}
fuzz_target=$1
if [[ -z $fuzz_target ]]; then
usage "No fuzz target provided"
fi
run_time=$2
if [[ -z $2 ]]; then
usage "No runtime provided"
fi
HFUZZ_RUN_ARGS="--run_time $run_time --exit_upon_crash" cargo +"$rust_stable" hfuzz run $fuzz_target
# Until https://github.com/rust-fuzz/honggfuzz-rs/issues/16 is resolved,
# hfuzz does not return an error code on crash, so look for a crash artifact
exit_status=0
for crash_file in ./hfuzz_workspace/"$fuzz_target"/*.fuzz; do
# Check if the glob gets expanded to existing files.
if [[ -e "$crash_file" ]]; then
echo "Error: .fuzz file $crash_file found, reproduce locally with the hexdump:"
od -t x1 "$crash_file"
crash_file_base=$(basename $crash_file)
hex_output_filename=hex_"$crash_file_base"
echo "Copy / paste this output into a normal file (e.g. $hex_output_filename)"
echo "Reconstruct the binary file using:"
echo "xxd -r $hex_output_filename > $crash_file_base"
echo "To reproduce the problem, run:"
echo "cargo hfuzz run-debug $fuzz_target $crash_file_base"
exit_status=1
fi
done
exit $exit_status