strawberry/scripts/run_fuzzers.sh
trvon 169a05cd2a
fuzz: target the YARA rule partitioner
rule_partition.cpp parses rule sources (splitting rules, extracting top-level
condition identifiers and facts), but had no fuzz target, contradicting the
repository rule that every parser of attacker-influenced input gets one.
fuzz_rule_partition asserts the splitter is a total, exact partition of its
input, that rule/condition slicing stays within the rule, and that partition
selection agrees with magic bytes and the size bucket boundaries.

It is registered in fuzz/meson.build (with rule_partition.cpp), swept by
scripts/run_fuzzers.sh, and documented next to the other targets. Seeds cover
comments, strings, regexes, hex blocks, an include and a truncated source.
2026-11-17 13:45:12 -07:00

33 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run each libFuzzer target for N seconds (default 60), one at a time, at low
# priority with a memory cap, keeping corpora in build/fuzz-corpus/<target>.
# Crashes land in build/fuzz-artifacts/<target>/ and fail the run.
set -uo pipefail
SECONDS_EACH="${1:-60}"
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BUILD="${FUZZ_BUILD:-$ROOT/build/fuzz}"
status=0
for target in fuzz_io_faults fuzz_ioc_list fuzz_policy_apply fuzz_governor_parsers fuzz_rule_partition fuzz_status_snapshot fuzz_config fuzz_record_decoder fuzz_block_decoder fuzz_segment_reader fuzz_manifest fuzz_evidence_records fuzz_legacy_kv fuzz_telemetry_records fuzz_cmdline_redactor fuzz_tokenizer fuzz_replay fuzz_trace_dsl fuzz_model_file fuzz_rarity_state fuzz_opensnitch_events fuzz_procargs fuzz_mcp_handle; do
bin="$BUILD/fuzz/$target"
[ -x "$bin" ] || { echo "skip $target (not built)"; continue; }
corpus="$ROOT/build/fuzz-corpus/$target"
artifacts="$ROOT/build/fuzz-artifacts/$target/"
mkdir -p "$corpus" "$artifacts"
seeds="$ROOT/fuzz/seeds/$target"
echo "== $target (${SECONDS_EACH}s)"
# LeakSanitizer needs ptrace, which yama ptrace_scope >= 2 forbids for
# non-root; leak checks are off here (ASan/UBSan stay on).
# UBSan recovers by default, which can otherwise make a bad run exit 0.
UBSAN_OPTIONS="${UBSAN_OPTIONS:+$UBSAN_OPTIONS:}halt_on_error=1" \
ASAN_OPTIONS="${ASAN_OPTIONS:-detect_leaks=0}" nice -n 19 "$bin" -max_total_time="$SECONDS_EACH" -rss_limit_mb=1024 -malloc_limit_mb=512 -timeout=10 \
-artifact_prefix="$artifacts" -print_final_stats=1 "$corpus" $( [ -d "$seeds" ] && echo "$seeds" ) \
> "$ROOT/build/fuzz-artifacts/$target.log" 2>&1
rc=$?
grep -E "^stat::number_of_executed_units|^stat::peak_rss_mb|cov: " "$ROOT/build/fuzz-artifacts/$target.log" | tail -3
if [ $rc -ne 0 ]; then
echo "FAIL $target (exit $rc): see build/fuzz-artifacts/$target.log"
grep -E "ERROR|SUMMARY|runtime error" "$ROOT/build/fuzz-artifacts/$target.log" | head -5
status=1
fi
done
exit $status