Skip to content

Commit f9da06d

Browse files
committed
Preliminary support for libfuzzer
1 parent 97c1d65 commit f9da06d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1641
-546
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,47 @@ jobs:
9999
cargo clean && cargo +nightly udeps --features=test-fuzz/auto_concretize --all-targets
100100
101101
test:
102-
runs-on: ubuntu-latest
103-
104102
strategy:
105103
matrix:
106-
serde_format: [bincode, cbor, cbor4ii]
107-
toolchain: [stable, nightly]
104+
include:
105+
- fuzzer: aflplusplus
106+
serde_format: bincode
107+
environment: ubuntu-latest
108+
toolchain: stable
109+
- fuzzer: aflplusplus
110+
serde_format: cbor
111+
environment: ubuntu-latest
112+
toolchain: nightly
113+
- fuzzer: aflplusplus
114+
serde_format: cbor4ii
115+
environment: macos-latest
116+
toolchain: stable
117+
- fuzzer: aflplusplus-persistent
118+
serde_format: bincode
119+
environment: macos-latest
120+
toolchain: nightly
121+
- fuzzer: aflplusplus-persistent
122+
serde_format: cbor
123+
environment: ubuntu-latest
124+
toolchain: stable
125+
- fuzzer: aflplusplus-persistent
126+
serde_format: cbor4ii
127+
environment: ubuntu-latest
128+
toolchain: nightly
129+
- fuzzer: libfuzzer
130+
serde_format: bincode
131+
environment: macos-latest
132+
toolchain: stable
133+
- fuzzer: libfuzzer
134+
serde_format: cbor
135+
environment: macos-latest
136+
toolchain: nightly
137+
- fuzzer: libfuzzer
138+
serde_format: cbor4ii
139+
environment: ubuntu-latest
140+
toolchain: stable
141+
142+
runs-on: ${{ matrix.environment }}
108143

109144
steps:
110145
- uses: actions/checkout@v3
@@ -113,6 +148,7 @@ jobs:
113148
run: rustup default ${{ matrix.toolchain }}
114149

115150
- name: Install llvm
151+
if: ${{ matrix.environment == 'ubuntu-latest' }}
116152
run: sudo apt-get install llvm
117153

118154
# smoelius: The Substrate tests require `protoc`.
@@ -123,6 +159,13 @@ jobs:
123159
- name: Install afl
124160
run: cargo install afl
125161

162+
- name: Run afl-system-config
163+
run: |
164+
sudo "$HOME"/.local/share/afl.rs/rustc-*/afl.rs-*/afl/bin/afl-system-config
165+
if [[ ${{ matrix.environment }} = 'macos-latest' ]]; then
166+
launchctl list
167+
fi
168+
126169
# smoelius: The wasm32 target is needed for some Substrate tests, regardless of the toolchain
127170
# used to build test-fuzz.
128171
- name: Add wasm32 target
@@ -136,18 +179,18 @@ jobs:
136179
AUTO_CONCRETIZE=
137180
IGNORED=
138181
SHUFFLE=
139-
if [[ ${{ matrix.toolchain }} = nightly ]]; then
182+
if [[ ${{ matrix.toolchain }} = 'nightly' ]]; then
140183
AUTO_CONCRETIZE='--features=test-fuzz/auto_concretize'
141184
SHUFFLE='-Z unstable-options --shuffle --test-threads=1'
142185
fi
143-
if [[ ${{ github.event_name }} = schedule ]]; then
186+
if [[ ${{ github.event_name }} = 'schedule' ]]; then
144187
IGNORED='--ignored'
145188
fi
146189
cargo test --features=test-fuzz/serde_${{ matrix.serde_format }} "$AUTO_CONCRETIZE" -- --nocapture $IGNORED $SHUFFLE
147190
env:
148-
AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES: 1
149191
RUST_BACKTRACE: 1
150192
RUST_LOG: warn
193+
TEST_FUZZ_FUZZER: ${{ matrix.fuzzer }}
151194

152195
test-uninstalled-cargo-afl:
153196
runs-on: ubuntu-latest
@@ -162,13 +205,14 @@ jobs:
162205
run: |
163206
OUTPUT="$(cargo run -p cargo-test-fuzz -- test-fuzz -p test-fuzz-examples --no-run 2>&1 1>/dev/null || true)"
164207
echo "$OUTPUT"
165-
echo "$OUTPUT" | grep '^Error: Could not determine `cargo-afl` version. Is it installed? Try `cargo install afl`.$'
208+
echo "$OUTPUT" | grep 'Could not determine `cargo-afl` version. Is it installed? Try `cargo install afl`.'
166209
167210
test-incompatible-cargo-afl:
168211
runs-on: ubuntu-latest
169212

170213
env:
171214
RUSTUP_TOOLCHAIN: nightly
215+
TEST_FUZZ_FUZZER: aflplusplus-persistent
172216

173217
steps:
174218
- uses: actions/checkout@v3
@@ -190,6 +234,7 @@ jobs:
190234

191235
env:
192236
RUSTUP_TOOLCHAIN: nightly
237+
TEST_FUZZ_FUZZER: aflplusplus-persistent
193238

194239
steps:
195240
- uses: actions/checkout@v3

README.md

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -248,50 +248,52 @@ The `cargo test-fuzz` command is used to interact with fuzz targets, and to mani
248248
#### Options
249249

250250
```
251-
--backtrace Display backtraces
252-
--consolidate Move one target's crashes, hangs, and work queue to its corpus; to
253-
consolidate all targets, use --consolidate-all
254-
--display <OBJECT> Display concretizations, corpus, crashes, `impl` concretizations,
255-
hangs, or work queue. By default, corpus uses an uninstrumented fuzz
256-
target; the others use an instrumented fuzz target. To display the
257-
corpus with instrumentation, use --display corpus-instrumented.
258-
[possible values: concretizations, corpus, corpus-instrumented,
259-
crashes, hangs, impl-concretizations, queue]
260-
--exact Target name is an exact name rather than a substring
261-
--exit-code Exit with 0 if the time limit was reached, 1 for other programmatic
262-
aborts, and 2 if an error occurred; implies --no-ui, does not imply
263-
--run-until-crash or -- -V <SECONDS>
264-
--features <FEATURES> Space or comma separated list of features to activate
265-
--list List fuzz targets
266-
--manifest-path <PATH> Path to Cargo.toml
267-
--no-default-features Do not activate the `default` feature
268-
--no-instrumentation Compile without instrumentation (for testing build process)
269-
--no-run Compile, but don't fuzz
270-
--no-ui Disable user interface
271-
-p, --package <PACKAGE> Package containing fuzz target
272-
--persistent Enable persistent mode fuzzing
273-
--pretty-print Pretty-print debug output when displaying/replaying
274-
--replay <OBJECT> Replay corpus, crashes, hangs, or work queue. By default, corpus uses
275-
an uninstrumented fuzz target; the others use an instrumented fuzz
276-
target. To replay the corpus with instrumentation, use --replay
277-
corpus-instrumented. [possible values: concretizations, corpus,
278-
corpus-instrumented, crashes, hangs, impl-concretizations, queue]
279-
--reset Clear fuzzing data for one target, but leave corpus intact; to reset
280-
all targets, use --reset-all
281-
--resume Resume target's last fuzzing session
282-
--run-until-crash Stop fuzzing once a crash is found
283-
--test <NAME> Integration test containing fuzz target
284-
--timeout <TIMEOUT> Number of milliseconds to consider a hang when fuzzing or replaying
285-
(equivalent to -- -t <TIMEOUT> when fuzzing)
286-
--verbose Show build output when displaying/replaying
287-
-h, --help Print help
288-
-V, --version Print version
289-
290-
To fuzz at most <SECONDS> of time, use:
291-
292-
cargo test-fuzz ... -- -V <SECONDS>
293-
294-
Try `cargo afl fuzz --help` to see additional fuzzer options.
251+
--backtrace Display backtraces
252+
--consolidate Move one target's crashes, hangs, and work queue to its corpus; to
253+
consolidate all targets, use --consolidate-all
254+
--display <OBJECT> Display concretizations, corpus, crashes, `impl` concretizations,
255+
hangs, or work queue. By default, corpus uses an uninstrumented
256+
fuzz target; the others use an instrumented fuzz target. To
257+
display the corpus with instrumentation, use --display
258+
corpus-instrumented. [possible values: concretizations, corpus,
259+
corpus-instrumented, crashes, hangs, impl-concretizations, queue]
260+
--exact Target name is an exact name rather than a substring
261+
--exit-code Exit with 0 if the time limit was reached, 1 for other
262+
programmatic aborts, and 2 if an error occurred; implies --no-ui,
263+
does not imply --run-until-crash or --max-total-time <SECONDS>
264+
--features <FEATURES> Space or comma separated list of features to activate
265+
--fuzzer <FUZZER> Fuzz using <FUZZER> [possible values: aflplusplus,
266+
aflplusplus-persistent, libfuzzer]
267+
--list List fuzz targets
268+
--manifest-path <PATH> Path to Cargo.toml
269+
--max-total-time <SECONDS> Fuzz at most <SECONDS> of time (equivalent to -- -V <SECONDS> for
270+
aflplusplus, and -- --max_total_time <SECONDS> for libfuzzer)
271+
--no-default-features Do not activate the `default` feature
272+
--no-instrumentation Compile without instrumentation (for testing build process)
273+
--no-run Compile, but don't fuzz
274+
--no-ui Disable user interface
275+
-p, --package <PACKAGE> Package containing fuzz target
276+
--pretty-print Pretty-print debug output when displaying/replaying
277+
--replay <OBJECT> Replay corpus, crashes, hangs, or work queue. By default, corpus
278+
uses an uninstrumented fuzz target; the others use an instrumented
279+
fuzz target. To replay the corpus with instrumentation, use
280+
--replay corpus-instrumented. [possible values: concretizations,
281+
corpus, corpus-instrumented, crashes, hangs, impl-concretizations,
282+
queue]
283+
--reset Clear fuzzing data for one target, but leave corpus intact; to
284+
reset all targets, use --reset-all
285+
--resume Resume target's last fuzzing session
286+
--run-until-crash Stop fuzzing once a crash is found
287+
--test <NAME> Integration test containing fuzz target
288+
--timeout <TIMEOUT> Number of milliseconds to consider a hang when fuzzing or
289+
replaying (equivalent to -- -t <TIMEOUT> when fuzzing with
290+
aflplusplus, and -- -timeout <TIMEOUT/1000> when fuzzing with
291+
libfuzzer)
292+
--verbose Show build output when displaying/replaying
293+
-h, --help Print help
294+
-V, --version Print version
295+
296+
Try `cargo afl fuzz --help` to see additional AFLplusplus options.
295297
```
296298

297299
### Convenience functions and macros

cargo-test-fuzz/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cargo-test-fuzz"
33
version = "3.0.5"
4-
edition = "2018"
4+
edition = "2021"
55

66
description = "cargo-test-fuzz"
77

@@ -17,18 +17,22 @@ path = "src/bin/cargo_test_fuzz.rs"
1717
doctest = false
1818

1919
[dependencies]
20-
anyhow = "1.0"
20+
anyhow = { version = "1.0", features = ["backtrace"] }
2121
bitflags = "2.2"
22+
cargo-fuzz = { git = "https://github.com/trail-of-forks/cargo-fuzz", features = ["no-manifest-check"] }
2223
cargo_metadata = "0.15"
2324
clap = { version = "4.2", features = ["cargo", "derive", "wrap_help"] }
2425
env_logger = "0.10"
26+
fs_extra = "1.3"
2527
heck = "0.4"
2628
lazy_static = "1.4"
2729
log = "0.4"
30+
once_cell = "1.16"
2831
paste = "1.0"
2932
remain = "0.2"
3033
semver = "1.0"
3134
serde = { version = "1.0", features = ["derive"] }
35+
serde_json = "1.0"
3236
strum_macros = "0.24"
3337
subprocess = "0.2"
3438

0 commit comments

Comments
 (0)