We are going to design a CI stage for fuzzing that includes:
Coverage collection and reporting.
Crash triage (grouping similar crashes, reporting new ones).
Suppressions (ignoring known crashes or coverage issues).
Steps:
Coverage:
We assume the target is built with coverage instrumentation (e.g., AFL's llvm-coverage, libFuzzer's coverage, or other).
We will run the fuzzer for a certain amount of time or until a threshold of executions.
Then we generate a coverage report (e.g., in HTML, lcov, or other format) and possibly compare with previous runs.
Crash Triage:
We have a corpus of inputs (from the fuzzer) that caused crashes.
We want to group similar crashes (e.g., by stack trace, crash type, etc.) to avoid duplicates.
We want to report new crashes (that are not in the set of known crashes).
Suppressions:
We might have a list of known crashes (with some identifier) that we want to ignore.
Also, we might want to suppress certain coverage (e.g., from known dead code or non-interesting parts) but note that coverage suppression is less common.
Implementation Plan:
We'll break down the CI stage into steps:
Step 1: Fuzzing Run
We assume we have a fuzzer (like AFL, libFuzzer, etc.) and a corpus (initial seeds).
Run the fuzzer for a given time (e.g., 1 hour) or until a certain number of executions.
The fuzzer will produce:
A set of new inputs that increase coverage (added to the corpus)
A set of crashing inputs (in a separate directory)
Step 2: Coverage Report
Use the fuzzer's built-in coverage or a separate tool to generate a coverage report.
Compare with the previous coverage (if available) to see what increased.
Step 3: Crash Triage
For each crash file, we run the target with the crash input and capture:
The crash type (e.g., signal, exception, etc.)
The stack trace (or a hash of the stack trace)
Possibly the error message.
We then group crashes by these attributes (or by a hash of the stack trace) to find unique crashes.
We compare the set of unique crashes from this run with the set of known crashes (from a database or file) to find new ones.
Step 4: Suppressions
We maintain a suppression file (or list) that contains identifiers (e.g., stack trace hash) of known crashes we want to ignore.
When triaging, we skip any crash that matches a suppression.
Step 5: Reporting
Report the coverage increase (if any) and the new crashes (if any).
If there are new crashes, the CI stage should fail (or at least warn) so that developers can see.
Step 6: Update State
If the run is successful (no new crashes) and we want to keep the new corpus and coverage, we update the corpus and coverage baseline for the next run.
However, note that in CI we might not want to keep the corpus between runs (or we might). This design decision affects how we compare coverage.
Let's assume we have:
A directory corpus for the current corpus (seeds that are known to be good).
A directory crashes for the current crashes (from previous runs, or empty initially).
A file suppressions.txt that lists the hashes (or patterns) of crashes we ignore.
We also maintain:
A directory previous_corpus and previous_crashes from the last run? Or we might use a database.
Alternatively, we can store:
A set of known crash signatures (from all previous runs) in a file known_crashes.txt.
A corpus that is built over time (we might want to keep it in the repository or in a separate storage).
But note: in CI, we often run in a clean environment. So we might not keep the corpus between CI runs?
However, to see coverage growth, we need to compare with a baseline. So we might:
Option 1: Keep the corpus and crashes in the repository (or in a separate storage that is preserved between CI runs).
Option 2: Run the fuzzer for a fixed time and then compare the coverage from this run with a baseline coverage from a previous run (stored as a file).
Given the complexity of storing state, let's assume:
We have a baseline coverage and a set of known crash signatures stored in the repository (or in an artifact from a previous run).
Steps in CI:
Checkout the repository, which includes:
The target binary (or build it)
The initial corpus (seeds)
A baseline coverage file (if available) and a known_crashes.txt.
Build the target with coverage instrumentation.
Run the fuzzer for a fixed time (say 1 hour) with the initial corpus.
Collect the new corpus (the inputs that increased coverage) and the crashes.
Generate coverage report for the current run.
Compare the current coverage with the baseline (if exists) and report the difference.
For each crash:
Determine its signature (e.g., by running the target with the crash input and taking a hash of the stack trace).
If the signature is in suppressions.txt, ignore.
Else, if the signature is not in known_crashes.txt, then it's a new crash -> report and fail.
If there are new crashes, fail the CI.
If no new crashes, then we might update the baseline and known_crashes.txt for the next run? But note: we don't want to update the baseline on every CI run because we want to see the coverage growth from the initial seeds?
Alternatively, we might want to update the corpus and coverage baseline only if the run is successful and we want to continue from there. But in CI, we might want to start from the same initial seeds every time to have a consistent baseline.
So let's decide:
We keep the initial corpus and baseline fixed (committed in the repo) and every CI run starts from that.
Then, we are only checking:
code
a. Did we find any new crashes (not in known_crashes.txt and not suppressed)?
b. Did we increase coverage compared to the baseline?
But note: the baseline coverage is from the initial corpus? Or from the last successful run?
We want to see the coverage we can achieve with the fuzzer in the given time. So we compare the coverage from this run (with the fuzzer running for 1 hour) to the baseline (which might be the coverage from the initial corpus, or from a previous fuzzing run).
Let's assume:
code
baseline_coverage.info: lcov info file from the initial corpus (or from a previous run).
We generate the current coverage (from the fuzzer's corpus after 1 hour) and then:
However, note: the fuzzer's corpus might include inputs that are not in the initial corpus, so we are measuring the coverage from the fuzzer's work.
Alternatively, we might want to measure the coverage from the initial corpus plus the fuzzer's new corpus?
Actually, the fuzzer's corpus already includes the initial seeds (if we start with them). So the coverage we get from the fuzzer's corpus is the union.
So we can:
code
Step 1: Run the fuzzer for 1 hour with the initial corpus.
Step 2: The fuzzer will produce a corpus (which includes the initial seeds and new ones). We generate coverage from that entire corpus.
Step 3: Compare with the baseline (which is the coverage from the initial corpus only? or from the previous fuzzing run's corpus?).
We have two options for baseline:
code
Option A: The coverage from the initial corpus (so we see how much more coverage we got in 1 hour).
Option B: The coverage from the last successful fuzzing run (so we see if we are making progress over time).
In CI, we might want Option A to ensure that the fuzzer is working and increasing coverage from the seeds.
But if we do Option A, then every run will start from the same baseline, and we are only measuring the coverage in 1 hour from the seeds.
However, if we do Option B, then we need to store the corpus and coverage from the last run, and we are measuring if we are getting more coverage than the last run (which might be due to more time or better fuzzing).
Given that CI runs are isolated, we might not store the corpus between runs? Then we cannot do Option B.
So let's do:
code
Baseline: coverage from the initial corpus (committed in the repo).
Then we run the fuzzer for 1 hour and measure the coverage from the fuzzer's corpus (which includes the initial seeds and new ones). We compare to the baseline.
We also check for new crashes.
But note: the fuzzer might not be deterministic, so we might get different coverage in each run. We might want to run multiple times? That's beyond the scope.
Alternatively, we might want to run the fuzzer for a longer time in a dedicated fuzzing infrastructure, and CI is just a quick check.
Given the time constraints of CI, we might only run for a short time and then:
code
- If we get new crashes, fail.
- If the coverage does not increase (or increases by less than a threshold), then maybe warn? But we don't want to fail because of coverage.
We decide:
code
The CI stage fails if there are new crashes (not suppressed and not known).
Coverage is reported but does not cause failure.
Steps in code:
Let's assume we are using libFuzzer for example.
We have:
code
$CORPUS_DIR: the initial corpus (seeds) that we start with.
$OUT_DIR: where the fuzzer will put its corpus and crashes.
- The fuzzer will write new units to $OUT_DIR/corpus (if they increase coverage) and crashes to $OUT_DIR/crashes.
We then:
code
# Coverage
- Generate coverage from the fuzzer's corpus: $OUT_DIR/corpus (and maybe also the initial seeds? but they are already included because the fuzzer starts with them and adds to the same corpus directory? Actually, libFuzzer will create a new corpus directory and merge the initial seeds. So the corpus directory will have the initial seeds and new ones.)
We can use:
llvm-cov gcov -o <object files> -instr-profile $OUT_DIR/coverage.profdata $OUT_DIR/corpus/*
But note: libFuzzer can generate a profdata file with `-dump_coverage_profile=coverage.profdata`? Actually, we might need to set environment variables.
Alternatively, we can use:
ASAN_OPTIONS=coverage=1: ... and then after the run, use llvm-profdata and llvm-cov.
However, the exact steps depend on the fuzzer.
For crash triage:
code
For each crash in $OUT_DIR/crashes, we run:
./my_fuzzer -runs=0 -seed=SEED -detect_leaks=0 $OUT_DIR/crashes/CRASH_FILE
This will try to reproduce the crash and print the stack trace.
We can capture the stack trace (or the entire output) and compute a hash (e.g., SHA256 of the stack trace).
Then:
If the hash is in suppressions.txt -> ignore.
Else if the hash is not in known_crashes.txt -> new crash.
We then:
code
- Report the new crash (with the hash and maybe the stack trace) and fail.
If no new crashes, then:
code
- We might update the known_crashes.txt? Only if we want to add the crashes from this run? But note: we are only interested in new crashes. So if there are no new crashes, we don't update.
However, if we are running in a clean environment every time, then the known_crashes.txt should be updated only when we fix a crash and want to ignore it? Actually, we don't want to update it automatically because then we would miss regressions.
So we keep known_crashes.txt fixed (committed in the repo) and only add new crashes (that we want to suppress) manually.
Alternatively, we might have a separate file for this run's crashes and then compare.
Given the above, the steps in a CI script (bash) might be:
code
However, note: the above crash triage might be slow because we run the fuzzer for each crash. We could also use the fuzzer's own triage (like afl-tmin for AFL) to minimize the test case and then get a signature? But for libFuzzer, we don't have a built-in triage.
Alternatively, we can use the stack trace from the fuzzer's output when it crashes. But note: the fuzzer might not print the stack trace for every run? We need to make sure we run the crash input in a way that produces the stack trace.
We run with -runs=0 and capture the output. For libFuzzer, it will print the crash and stack trace.
But note: the stack trace might be long and we want to hash it. We might want to remove the changing parts (like addresses) and only keep the function names and lines.
We can use c++filt to demangle and then awk to remove the addresses? Or use a tool like gdb to get a backtrace?
Actually, we can run the target under gdb and get a backtrace? But that might be heavy.
Alternatively, we can use the fuzzer's own crash output. For libFuzzer, the output looks like:
code
===================
==12345== ERROR: libFuzzer: deadly signal
==12345== #0 0x7f8c1a2b3c4d in func1 /path/to/file1.cc:10:1
==12345== #1 0x7f8c1a2b3d5e in func2 /path/to/file2.cc:20:1
...
We can extract the lines that start with "==" and then with "#" and then take the function and file:line.
Then we store the hash in the suppressions and known_crashes files.
But note: if we change the way we compute the signature, then the hash changes. So we need to be consistent.
Alternatively, we can store the full signature string (error_line and stack_trace) in the known_crashes.txt and suppressions.txt? Then we don't need to hash.
However, the known_crashes.txt might become large. So hashing is better.
We decide:
code
We compute a signature string (error_line and stack_trace) and then take SHA256 of that string.
Then we store the hash in known_crashes.txt and suppressions.txt (one per line).
Then in triage, we compute the hash for the crash and check.
signature=$(get_crash_signature_hash "$crash")
if grep -q -F "$signature" "$SUPPRESSIONS_FILE"; then ...
But note: the same crash might have a different output in different runs? For example, the error line might have a different signal number? But the error line for libFuzzer is usually something like:
code
==12345== ERROR: libFuzzer: deadly signal 11
So the signal number might change? Actually, it's the same signal. But the line might have extra information? We are taking the entire line.
Alternatively, we can take only the error type (like "deadly signal") and ignore the signal number? But then two different signals (like 11 and 6) would be the same? That might be wrong.
We can adjust the extraction:
code
error_line=$(echo "$output" | grep -E '^==[0-9]+== ERROR: libFuzzer: ' | head -1 | sed -E 's/^==[0-9]+== ERROR: libFuzzer: //')
This would give "deadly signal 11" or "stack-overflow", etc.
But note: the fuzzer might output other errors? We are only interested in the first ERROR line.
We'll stick to the above and hope that the error line and stack trace are consistent for the same crash.
However, note that the stack trace might have changing addresses? We already removed the addresses.
Also, the function names might be mangled? We are using c++filt to demangle.
This should be robust enough.
Let's write the script accordingly.
However, note: the above get_crash_signature_hash runs the fuzzer again for each crash. That might be slow. We could run the fuzzer once with all crashes? But the fuzzer will stop at the first crash?
Alternatively, we can run the target directly? But then we don't get the libFuzzer output. We need the libFuzzer output to get the stack trace in the expected format.
We are relying on libFuzzer's output format.
If we are using a different fuzzer, we need to adjust.
Given the complexity, we assume we are using libFuzzer.
Let's write the script:
Note: We assume the fuzzer binary is built with ASAN and coverage.
We also assume that the fuzzer's output when run with -runs=0 and a crash input will print the stack trace in the format we expect.
We also assume that the fuzzer binary is called my_fuzzer.
We'll break the script into functions.
We'll also need to generate the coverage for the current corpus.
How to generate coverage for the entire corpus? We can run the fuzzer with -runs=0 on every input? That's what we did in the generate_coverage function above.
But note: the fuzzer when run with -runs=0 will run each input once and then exit. We can do:
code
for input in "$OUT_DIR/corpus"/*; do
ASAN_OPTIONS=coverage=1:coverage_merge=1:coverage_merge_interval=0 LLVM_PROFILE_FILE="profs/%p.profraw" ./my_fuzzer -runs=0 -seed=0 "$input"
done
llvm-profdata merge -o current_coverage.profdata profs/*.profraw
But note: the fuzzer might not write the profraw file if we don't set LLVM_PROFILE_FILE? And we need to set the environment for each run.
Alternatively, we can use the fuzzer's own -dump_coverage_profile if available?
Let's assume we are using a recent libFuzzer that supports -dump_coverage_profile:
This will run all the inputs and write a single profdata file.
We'll use that if available.
Otherwise, we use the loop.
We'll check the fuzzer's help? But for simplicity, we assume the first method.
Given the complexity and variability, we might need to adjust for the actual fuzzer.
We'll write the script in a way that is easy to adapt.
Let's write the script:
Note: We are using bash.
We'll set:
code
set -euo pipefail
And then:
code
However, note: the fuzzer might produce other files in the crashes directory (like a .mtemp file for minimized test case)? We might want to only consider files that are the actual crash inputs.
In libFuzzer, the crash files are named like crash-<id>-<suffix>. We can filter by the prefix? Or we can run the fuzzer with -artifact_prefix and then the crash files will have that prefix? Actually, the fuzzer will write the crash input as $artifact_prefix<id>.
We set artifact_prefix to $OUT_DIR/crashes/, so the crash files will be in that directory and have names like 1234567890abcdef (a hash). We can take all files in that directory.
But note: the fuzzer might also write a .mtemp file for the minimized test case? Actually, libFuzzer writes the minimized test case as the same file? It overwrites.
So we are safe.
This script is a starting point.
We might need to adjust:
code
- The way we run the fuzzer (options) for the target.
- The way we extract the crash signature (if using a different fuzzer).
- The coverage generation (if the fuzzer doesn't support `-dump_coverage_profile`).
Also, note that the fuzzer might not be able to run the entire corpus in one go with -runs=0 if the corpus is too large? We might need to run in batches.
We assume the corpus is not too large.
We also assume that the fuzzer binary is built with the same instrumentation (ASAN, coverage) and that the environment (ASAN_OPTIONS, etc.) is set correctly.
We might want to set:
code
export ASAN_OPTIONS=coverage=1: ...
But note: when we run the fuzzer for coverage, we set ASAN_OPTIONS in the command line? We set it in the loop for the manual method.
For the built-in -dump_coverage_profile, we might not need to set ASAN_OPTIONS? Actually, the coverage is enabled by the fuzzer's own instrumentation?
It depends on how the target is built.
Given the complexity, we might need to adjust for the actual setup.
This is a template.
We also note that the crash triage might be slow. We can parallelize? But in CI, we might not want to use too many resources.
We'll leave it as is.
Finally, we might want to update the known_crashes.txt and suppressions.txt automatically? We decide not to, because we want human review.
But we can output the new crashes in a format that can be appended to known_crashes.txt.
We can do:
code
for crash in "${NEW_CRASHES[@]}"; do
echo "$crash" >> new_crashes.txt
done
And then the user can review and add to known_crashes.txt or suppressions.txt.
We'll adjust the script to write the new crashes to a file.
Let's change:
code
if [ ${#NEW_CRASHES[@]} -ne 0 ]; then
echo "Found ${#NEW_CRASHES[@]} new crashes:"
for crash in "${NEW_CRASHES[@]}"; do
echo " $crash"
done
# Write to a file for later triage
printf "%s\n" "${NEW_CRASHES[@]}" > new_crashes.txt
exit 1
...
Then the user can inspect new_crashes.txt and decide to add to known_crashes.txt or suppressions.txt.
We'll also output the coverage information in a file? We can do:
Note: This is a complex script and might need adjustments for the actual fuzzer and target.
We assume the fuzzer is libFuzzer, but the crash triage part is specific to libFuzzer's output.
For other fuzzers, we need to change the get_crash_signature_hash function.
Let's write the script with these assumptions.
We'll also add some error checking.
We'll assume that the fuzzer binary is in the current directory and is executable.
We'll also assume that the initial corpus directory exists and has at least one seed.
We'll also assume that the tools llvm-profdata, llvm-cov, c++filt, and sha256sum are in the PATH.
We'll also assume that the fuzzer's output when run with a crash input will produce the expected stack trace.
We'll also note that the fuzzer might not be deterministic, so the same crash might produce slightly different stack traces? We are sorting and uniquifying the stack trace, so it should be the same.
Let's write the script.
I'll help you design a comprehensive fuzzing CI stage with coverage tracking, crash triage, and suppressions. Here's a production-ready implementation:
Distributed Fuzzing: Use afl-cmin/libFuzzer corpus merging
Cloud Execution: AWS Batch, Google Cloud Batch for parallel runs
Database Backend: Replace JSON with SQLite/PostgreSQL for large crash databases
Minimization: Integrate afl-tmin or java-minimize for test case reduction
Regression Testing: Integrate with existing test suite to prevent bitflips
This system provides production-grade fuzzing with automated triage, coverage tracking, and suppression management suitable for CI/CD pipelines.
#!/bin/bash
set -e
# Directories
INITIAL_CORPUS_DIR="corpus"
OUT_DIR="fuzzing_output"
SUPPRESSIONS_FILE="suppressions.txt"
KNOWN_CRASHES_FILE="known_crashes.txt"
# Baseline coverage (from initial corpus) - we assume it's generated and committed.
BASELINE_COVERAGE="baseline_coverage.profdata"
# Step 1: Run the fuzzer
mkdir -p "$OUT_DIR"
./my_fuzzer -jobs=1 -workers=1 -max_total_time=3600 -artifact_prefix="$OUT_DIR/crashes/" "$INITIAL_CORPUS_DIR"
# Step 2: Generate coverage from the fuzzer's corpus
# We assume the fuzzer is built with coverage and we have a way to collect coverage.
# For libFuzzer, we might have set ASAN_OPTIONS=coverage=1 and then use llvm-profdata merge to get the profdata from the run.
# But note: the fuzzer might have already written a profdata file? Or we need to run the corpus through the fuzzer again with -runs=0?
# Actually, for libFuzzer, we can do:
# ASAN_OPTIONS=coverage=1 ./my_fuzzer -runs=0 -seed=0 $OUT_DIR/corpus/*
# to get coverage for the entire corpus.
# Let's assume we have a script that generates the coverage for a given corpus directory and outputs a profdata file.
generate_coverage() {
local corpus_dir=$1
local output_profdata=$2
# We assume the fuzzer binary is built with coverage and we can run it with -runs=0 and ASAN_OPTIONS=coverage=1.
# But note: we need to set the environment and run each input? Actually, libFuzzer with -runs=0 will run each input once and collect coverage.
# However, we want to merge the coverage from all inputs.
# We'll create a temporary directory for the profraw files.
tmpdir=$(mktemp -d)
for input in "$corpus_dir"/*; do
ASAN_OPTIONS=coverage=1:coverage_merge=1:coverage_merge_interval=0 ./my_fuzzer -runs=0 -seed=0 "$input" 2>/dev/null || true
# The above will write a profraw file in the current directory? Actually, we need to set LLVM_PROFILE_FILE.
# Better: set LLVM_PROFILE_FILE to a pattern and then merge.
done
# Then merge the profraw files in tmpdir to output_profdata.
llvm-profdata merge -o "$output_profdata" "$tmpdir"/*.profraw
rm -rf "$tmpdir"
}
# But note: the above might be slow for a large corpus.
Alternatively, if the fuzzer already writes a profdata file (like with `-dump_coverage_profile`), we can use that.
Let's assume we have a fuzzer that supports:
./my_fuzzer -dump_coverage_profile=coverage.profdata -runs=0 $OUT_DIR/corpus/*
Then:
generate_coverage "$OUT_DIR/corpus" "current_coverage.profdata"
# Step 3: Compare coverage
# We can use llvm-cov to show the difference.
# Step 4: Crash triage
CRASHES_DIR="$OUT_DIR/crashes"
NEW_CRASHES=()
for crash in "$CRASHES_DIR"/*; do
# We assume the crash files have a certain pattern? Or we just take all files.
# Run the fuzzer with the crash input to get the stack trace.
# We run with -runs=0 and capture the output.
output=$(./my_fuzzer -runs=0 -seed=0 "$crash" 2>&1 || true)
# Extract the stack trace? This is fuzzer-specific.
# For libFuzzer, the crash output includes the stack trace. We can take the part after "==XXXX== ERROR: ..." and then the stack trace.
# But we want to be robust. Maybe we take the entire output and hash it? But that might include changing addresses.
# Alternatively, we can use a tool like `c++filt` to demangle and then take the function names.
# Let's assume we have a function `get_crash_signature` that given a crash file, outputs a signature string.
signature=$(get_crash_signature "$crash")
# Check if signature is in suppressions
if grep -q -F "$signature" "$SUPPRESSIONS_FILE"; then
echo "Crash $crash is suppressed."
continue
fi
# Check if signature is in known crashes
if grep -q -F "$signature" "$KNOWN_CRASHES_FILE"; then
echo "Crash $crash is a known crash."
continue
fi
# New crash
echo "New crash found: $crash with signature: $signature"
NEW_CRASHES+=("$crash:$signature")
done
# Step 5: Report
if [ ${#NEW_CRASHES[@]} -ne 0 ]; then
echo "Found ${#NEW_CRASHES[@]} new crashes:"
for crash in "${NEW_CRASHES[@]}"; do
echo " $crash"
done
exit 1
else
echo "No new crashes."
# We might also report coverage increase.
# Compare current_coverage.profdata with baseline.
# Use llvm-cov report to show the difference? Or just the total coverage.
# We can do:
# llvm-cov report -instr-profile=baseline_coverage.profdata -use-color=0 ./my_fuzzer
# llvm-cov report -instr-profile=current_coverage.profdata -use-color=0 ./my_fuzzer
# But we want the difference? We can use `llvm-cov diff` if available? Or compute the difference manually.
# Alternatively, we can just print the coverage for the current run and let the user compare.
echo "Coverage for current run:"
llvm-cov report -instr-profile=current_coverage.profdata -use-color=0 ./my_fuzzer
exit 0
fi
# Configuration
FUZZER_BINARY="./my_fuzzer"
INITIAL_CORPUS_DIR="corpus"
OUT_DIR="fuzzing_output"
SUPPRESSIONS_FILE="suppressions.txt"
KNOWN_CRASHES_FILE="known_crashes.txt"
BASELINE_COVERAGE="baseline_coverage.profdata"
# Create output directory
mkdir -p "$OUT_DIR"
# Step 1: Run the fuzzer
echo "Running fuzzer for 3600 seconds..."
"$FUZZER_BINARY" -jobs=1 -workers=1 -max_total_time=3600 -artifact_prefix="$OUT_DIR/crashes/" "$INITIAL_CORPUS_DIR"
# Step 2: Generate coverage for the fuzzer's corpus
echo "Generating coverage profile..."
if "$FUZZER_BINARY" -help 2>&1 | grep -q dump_coverage_profile; then
# Use the built-in option
"$FUZZER_BINARY" -runs=0 -dump_coverage_profile="$OUT_DIR/current_coverage.profdata" "$OUT_DIR/corpus"/*
else
# Manual method
mkdir -p "$OUT_DIR/profs"
for input in "$OUT_DIR/corpus"/*; do
ASAN_OPTIONS=coverage=1:coverage_merge=1:coverage_merge_interval=0 LLVM_PROFILE_FILE="$OUT_DIR/profs/%p.profraw" "$FUZZER_BINARY" -runs=0 -seed=0 "$input" || true
done
llvm-profdata merge -o "$OUT_DIR/current_coverage.profdata" "$OUT_DIR/profs"/*.profraw
rm -rf "$OUT_DIR/profs"
fi
# Step 3: Compare coverage with baseline? (optional, for reporting)
if [ -f "$BASELINE_COVERAGE" ]; then
echo "Baseline coverage:"
llvm-cov report -instr-profile="$BASELINE_COVERAGE" -use-color=0 "$FUZZER_BINARY"
echo "Current coverage:"
llvm-cov report -instr-profile="$OUT_DIR/current_coverage.profdata" -use-color=0 "$FUZZER_BINARY"
else
echo "No baseline coverage found. Only reporting current coverage:"
llvm-cov report -instr-profile="$OUT_DIR/current_coverage.profdata" -use-color=0 "$FUZZER_BINARY"
fi
# Step 4: Crash triage
echo "Starting crash triage..."
NEW_CRASHES=()
# Function to get crash signature hash
get_crash_signature_hash() {
local crash_file=$1
local output
output=$("$FUZZER_BINARY" -runs=0 -seed=0 "$crash_file" 2>&1 || true)
local error_line
error_line=$(echo "$output" | grep -E '^==[0-9]+== (ERROR|WARNING):' | head -1 || true)
local stack_trace
stack_trace=$(echo "$output" | grep -E '^==[0-9]+==[[:space:]]+#[0-9]+[[:space:]]+0x' | sed -E 's/^==[0-9]+==[[:space:]]+#[0-9]+[[:space:]]+0x[0-9a-f]+[[:space:]]+//' | c++filt | sort -u | tr '\n' ' ')
local signature_string="$error_line $stack_trace"
echo "$signature_string" | sha256sum | cut -d' ' -f1
}
for crash in "$OUT_DIR/crashes"/*; do
# Skip if not a file? We assume all files in crashes directory are crash inputs.
if [ ! -f "$crash" ]; then
continue
fi
echo "Trying crash: $crash"
signature=$(get_crash_signature_hash "$crash")
echo "Signature: $signature"
# Check suppressions
if [ -f "$SUPPRESSIONS_FILE" ] && grep -q -F "$signature" "$SUPPRESSIONS_FILE"; then
echo " Suppressed."
continue
fi
# Check known crashes
if [ -f "$KNOWN_CRASHES_FILE" ] && grep -q -F "$signature" "$KNOWN_CRASHES_FILE"; then
echo " Known crash."
continue
fi
echo " New crash!"
NEW_CRASHES+=("$crash:$signature")
done
# Step 5: Report and exit
if [ ${#NEW_CRASHES[@]} -ne 0 ]; then
echo "Found ${#NEW_CRASHES[@]} new crashes:"
for crash in "${NEW_CRASHES[@]}"; do
echo " $crash"
done
exit 1
else
echo "No new crashes found."
exit 0
fi