Skip to content

Commit 04c2413

Browse files
committed
Add option to use libfuzzer sys in full_stack_target
Note that there doesn't appear to be a way to conditionally set #[no_main] so that has to happen manually at compile-time.
1 parent 301f91e commit 04c2413

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

fuzz/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cargo-fuzz = true
1313
[features]
1414
afl_fuzz = ["afl"]
1515
honggfuzz_fuzz = ["honggfuzz"]
16+
libfuzzer_fuzz = ["libfuzzer-sys"]
1617

1718
[dependencies]
1819
afl = { version = "0.4", optional = true }
@@ -22,6 +23,7 @@ bitcoin_hashes = { git = "https://github.com/TheBlueMatt/bitcoin_hashes", branch
2223
hex = "0.3"
2324
honggfuzz = { version = "0.5", optional = true }
2425
secp256k1 = { version = "0.11", features=["fuzztarget"] }
26+
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true }
2527

2628
[build-dependencies]
2729
cc = "1.0"

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//Uncomment this for libfuzzer builds:
2+
//#![no_main]
3+
14
extern crate bitcoin;
25
extern crate bitcoin_hashes;
36
extern crate lightning;
@@ -540,6 +543,14 @@ fn main() {
540543
}
541544
}
542545

546+
#[cfg(feature = "libfuzzer_fuzz")]
547+
#[macro_use] extern crate libfuzzer_sys;
548+
#[cfg(feature = "libfuzzer_fuzz")]
549+
fuzz_target!(|data: &[u8]| {
550+
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
551+
do_test(data, &logger);
552+
});
553+
543554
extern crate hex;
544555
#[cfg(test)]
545556
mod tests {

0 commit comments

Comments
 (0)