Merge pull request 'fuzz: cargo-fuzz harness for the ratchet/qr/dispatch/file parsers' (#103) from wt/t_1265efb2 into main
Reviewed-on: #103
This commit is contained in:
commit
2f6f737106
30 changed files with 6645 additions and 0 deletions
61
scripts/run-fuzz.sh
Executable file
61
scripts/run-fuzz.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env sh
|
||||
# Run an OnionWire fuzz target. Needs a nightly toolchain and cargo-fuzz:
|
||||
#
|
||||
# rustup toolchain install nightly --profile minimal
|
||||
# cargo install cargo-fuzz
|
||||
#
|
||||
# `cargo` must be rustup's shim, not a distro package: the `+nightly` directive
|
||||
# only works through rustup. `export PATH="$HOME/.cargo/bin:$PATH"` if in doubt.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/run-fuzz.sh # all four targets, 60s each
|
||||
# scripts/run-fuzz.sh qr_decode # one target
|
||||
# FUZZ_SECS=300 scripts/run-fuzz.sh ratchet_frame
|
||||
# FUZZ_JOBS=4 scripts/run-fuzz.sh # fork N workers per target
|
||||
#
|
||||
# Every target is a pure parser/decryptor over untrusted peer input, so a
|
||||
# non-zero exit means libFuzzer found a crash: the reproducer lands in
|
||||
# fuzz/artifacts/<target>/ and is named crash-<hash>.
|
||||
#
|
||||
# Reproduce a crash without fuzzing:
|
||||
# cargo +nightly fuzz run <target> fuzz/artifacts/<target>/crash-<hash>
|
||||
#
|
||||
# Fold a fixed crash into the regression seeds (committed, so it runs every time
|
||||
# instead of being rediscovered):
|
||||
# cp fuzz/artifacts/<target>/crash-<hash> fuzz/seeds/<target>/
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
TARGETS="ratchet_frame qr_decode dispatch_classify file_decode"
|
||||
SECS="${FUZZ_SECS:-60}"
|
||||
JOBS="${FUZZ_JOBS:-1}"
|
||||
|
||||
# A build tree per machine, outside the repo: the fuzz crate links the whole
|
||||
# onionwire graph (Arti, SQLCipher, vendored OpenSSL) and must not share a
|
||||
# target dir with a stable build.
|
||||
: "${CARGO_TARGET_DIR:=$HOME/.cargo/fuzz-target}"
|
||||
export CARGO_TARGET_DIR
|
||||
: "${TMPDIR:=/var/tmp/onionwire-fuzz-tmp}"
|
||||
export TMPDIR
|
||||
mkdir -p "$TMPDIR"
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
TARGETS="$*"
|
||||
fi
|
||||
|
||||
for t in $TARGETS; do
|
||||
if [ ! -d "fuzz/corpus/$t" ]; then
|
||||
mkdir -p "fuzz/corpus/$t"
|
||||
fi
|
||||
# Seed the working corpus from fuzz/seeds (hand-built regression inputs).
|
||||
# fuzz/corpus itself is gitignored: libFuzzer grows it, and that growth is
|
||||
# machine-local noise, not source.
|
||||
cp -n fuzz/seeds/"$t"/* "fuzz/corpus/$t"/ 2>/dev/null || true
|
||||
|
||||
printf '\n=== fuzz %s (%ss, %s jobs) ===\n' "$t" "$SECS" "$JOBS"
|
||||
cargo +nightly fuzz run "$t" -j "$JOBS" -- -max_total_time="$SECS"
|
||||
done
|
||||
|
||||
printf '\nall targets survived %ss each\n' "$SECS"
|
||||
|
||||
Loading…
Reference in a new issue