Skip to content

Commit 455ca39

Browse files
authored
Merge pull request dtolnay#376 from dtolnay/honggfuzz
Add honggfuzz support to fuzz target
2 parents e9e5eb8 + 75d9042 commit 455ca39

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ jobs:
9999
- run: cargo fuzz check
100100
- run: cargo check --no-default-features --features afl
101101
working-directory: fuzz
102-
102+
- uses: dtolnay/install@honggfuzz
103+
- run: sudo apt-get install binutils-dev libunwind-dev
104+
- run: cargo hfuzz build --no-default-features --features honggfuzz
105+
working-directory: fuzz
103106

104107
clippy:
105108
name: Clippy

fuzz/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
artifacts/
22
corpus/
33
coverage/
4+
hfuzz_target/
5+
hfuzz_workspace/
46
in/
57
out/
68
target/

fuzz/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ cargo-fuzz = true
1010

1111
[dependencies]
1212
afl = { version = "0.12", optional = true }
13+
honggfuzz = { version = "0.5", optional = true }
1314
libfuzzer-sys = { version = "0.4", optional = true }
1415
proc-macro2 = { path = "..", default-features = false }
1516

1617
[features]
1718
default = ["libfuzzer"]
1819
afl = ["dep:afl"]
20+
honggfuzz = ["dep:honggfuzz"]
1921
libfuzzer = ["dep:libfuzzer-sys"]
2022
span-locations = ["proc-macro2/span-locations"]
2123

fuzz/fuzz_targets/parse_token_stream.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,37 @@
88
// cargo install afl
99
// cargo afl build --no-default-features --features afl --release
1010
// cargo afl fuzz -i in -o out target/release/parse_token_stream
11+
//
12+
// honggfuzz:
13+
//
14+
// cargo install honggfuzz
15+
// cargo hfuzz build --no-default-features --features honggfuzz
16+
// HFUZZ_RUN_ARGS="--threads $(nproc) --max_file_size 200 --timeout 1" cargo hfuzz run parse_token_stream
1117

1218
#![cfg_attr(feature = "libfuzzer", no_main)]
1319

1420
use std::str;
1521

1622
#[cfg(not(any(
17-
all(feature = "libfuzzer", not(feature = "afl")),
18-
all(not(feature = "libfuzzer"), feature = "afl"),
23+
all(
24+
feature = "libfuzzer",
25+
not(feature = "afl"),
26+
not(feature = "honggfuzz")
27+
),
28+
all(
29+
not(feature = "libfuzzer"),
30+
feature = "afl",
31+
not(feature = "honggfuzz")
32+
),
33+
all(
34+
not(feature = "libfuzzer"),
35+
not(feature = "afl"),
36+
feature = "honggfuzz"
37+
),
1938
)))]
2039
fn main() {
2140
compile_error! {
22-
r#"exactly one of feature="libfuzzer" and feature="afl" must be enabled"#
41+
r#"exactly one of feature="libfuzzer" or feature="afl" or feature="honggfuzz" must be enabled"#
2342
}
2443
}
2544

@@ -32,6 +51,13 @@ fn main() {
3251
afl::fuzz(hook, do_fuzz);
3352
}
3453

54+
#[cfg(feature = "honggfuzz")]
55+
fn main() {
56+
loop {
57+
honggfuzz::fuzz(do_fuzz);
58+
}
59+
}
60+
3561
fn do_fuzz(bytes: &[u8]) {
3662
if bytes.len() < 200 {
3763
if let Ok(string) = str::from_utf8(bytes) {

0 commit comments

Comments
 (0)