Skip to content

Commit 2ad33f8

Browse files
authored
Merge pull request #91 from alexcrichton/cargo-fuzz-in-ci
Migrate to using `cargo fuzz` in CI
2 parents 76f10a7 + f6d78f0 commit 2ad33f8

File tree

17 files changed

+156
-60
lines changed

17 files changed

+156
-60
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ jobs:
2020
rustup component add rustfmt --toolchain stable
2121
cargo +stable fmt --all -- --check
2222
23+
- run: cargo install cargo-fuzz
24+
2325
- name: Run tests
2426
run: ./ci/script.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target
22
Cargo.lock
3+
corpus

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ arbitrary-derive = ["arbitrary/derive"]
2020

2121
[workspace]
2222
members = [
23-
"./example",
24-
"./example_arbitrary",
25-
"./example_mutator",
23+
"./example/fuzz",
24+
"./example_arbitrary/fuzz",
25+
"./example_mutator/fuzz",
2626
]
2727

2828
[dev-dependencies]

ci/script.sh

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,26 @@ export CARGO_TARGET_DIR=$(pwd)/target
88
cargo test --doc
99

1010
pushd ./example
11-
cargo rustc \
12-
--release \
13-
-- \
14-
-Ccodegen-units=1 \
15-
-Cpasses=sancov-module \
16-
-Cllvm-args=-sanitizer-coverage-level=3 \
17-
-Cllvm-args=-sanitizer-coverage-trace-compares \
18-
-Cllvm-args=-sanitizer-coverage-inline-8bit-counters \
19-
-Cllvm-args=-sanitizer-coverage-stack-depth \
20-
-Cllvm-args=-sanitizer-coverage-trace-geps \
21-
-Cllvm-args=-sanitizer-coverage-prune-blocks=0 \
22-
-Zsanitizer=address
23-
(! $CARGO_TARGET_DIR/release/example -runs=100000)
11+
cargo fuzz build
12+
cargo fuzz build --dev
13+
(! cargo fuzz run bananas -- -runs=100000)
2414
popd
2515

2616
pushd ./example_arbitrary
27-
cargo rustc \
28-
--release \
29-
-- \
30-
-Ccodegen-units=1 \
31-
-Cpasses=sancov-module \
32-
-Cllvm-args=-sanitizer-coverage-level=3 \
33-
-Cllvm-args=-sanitizer-coverage-trace-compares \
34-
-Cllvm-args=-sanitizer-coverage-inline-8bit-counters \
35-
-Cllvm-args=-sanitizer-coverage-stack-depth \
36-
-Cllvm-args=-sanitizer-coverage-trace-geps \
37-
-Cllvm-args=-sanitizer-coverage-prune-blocks=0 \
38-
-Zsanitizer=address
39-
(! $CARGO_TARGET_DIR/release/example_arbitrary -runs=10000000)
17+
cargo fuzz build
18+
cargo fuzz build --dev
19+
(! cargo fuzz run rgb -- -runs=10000000)
4020
RUST_LIBFUZZER_DEBUG_PATH=$(pwd)/debug_output \
41-
$CARGO_TARGET_DIR/release/example_arbitrary \
42-
$(ls ./crash-* | head -n 1)
21+
cargo fuzz run rgb \
22+
$(ls ./fuzz/artifacts/rgb/crash-* | head -n 1)
4323
cat $(pwd)/debug_output
4424
grep -q Rgb $(pwd)/debug_output
4525
popd
4626

4727
pushd ./example_mutator
48-
cargo rustc \
49-
--release \
50-
-- \
51-
-Ccodegen-units=1 \
52-
-Cpasses=sancov-module \
53-
-Cllvm-args=-sanitizer-coverage-level=3 \
54-
-Cllvm-args=-sanitizer-coverage-trace-compares \
55-
-Cllvm-args=-sanitizer-coverage-inline-8bit-counters \
56-
-Cllvm-args=-sanitizer-coverage-stack-depth \
57-
-Cllvm-args=-sanitizer-coverage-trace-geps \
58-
-Cllvm-args=-sanitizer-coverage-prune-blocks=0 \
59-
-Zsanitizer=address
60-
(! $CARGO_TARGET_DIR/release/example_mutator -runs=10000000)
28+
cargo fuzz build
29+
cargo fuzz build --dev
30+
(! cargo fuzz run boom -- -runs=10000000)
6131
popd
6232

6333
echo "All good!"

example/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[package]
22
name = "example"
33
version = "0.1.0"
4-
authors = ["Simonas Kazlauskas <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
8-
libfuzzer-sys = { path = ".." }

example/fuzz/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "example-fuzz"
3+
version = "0.1.0"
4+
authors = ["Simonas Kazlauskas <[email protected]>"]
5+
edition = "2018"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = { path = "../.." }
12+
example = { path = ".." }
13+
14+
[[bin]]
15+
name = "bananas"
16+
path = "fuzz_targets/bananas.rs"

example/src/main.rs renamed to example/fuzz/fuzz_targets/bananas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ fuzz_target!(|data: &[u8]| {
66
if data == "banana!".as_bytes() {
77
panic!("success!");
88
}
9+
example::bananas(data);
910
});

example/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn bananas(data: &[u8]) {
2+
if data == &b"banana!"[..] {
3+
panic!("success!");
4+
}
5+
}

example_arbitrary/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ version = "0.1.0"
44
authors = ["Simonas Kazlauskas <[email protected]>"]
55
edition = "2018"
66

7-
[dependencies]
8-
libfuzzer-sys = { path = "..", features = ["arbitrary-derive"] }
7+
[target.'cfg(fuzzing)'.dependencies]
8+
arbitrary = "1"

example_arbitrary/fuzz/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "example_arbitrary_fuzz"
3+
version = "0.1.0"
4+
authors = ["Simonas Kazlauskas <[email protected]>"]
5+
edition = "2018"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = { path = "../..", features = ["arbitrary-derive"] }
12+
example_arbitrary = { path = ".." }
13+
14+
[[bin]]
15+
name = "rgb"
16+
path = "fuzz_targets/rgb.rs"

0 commit comments

Comments
 (0)