From cdf9b4f8ba3ded10017416a9e1d67ae184951df7 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 3 Dec 2018 13:56:44 -0500 Subject: [PATCH] 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. --- fuzz/Cargo.toml | 2 ++ fuzz/fuzz_targets/full_stack_target.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index c4ed4c703..dbdb69d2e 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -13,6 +13,7 @@ cargo-fuzz = true [features] afl_fuzz = ["afl"] honggfuzz_fuzz = ["honggfuzz"] +libfuzzer_fuzz = ["libfuzzer-sys"] [dependencies] afl = { version = "0.4", optional = true } @@ -22,6 +23,7 @@ bitcoin_hashes = { git = "https://github.com/TheBlueMatt/bitcoin_hashes", branch hex = "0.3" honggfuzz = { version = "0.5", optional = true } secp256k1 = { version = "0.11", features=["fuzztarget"] } +libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true } [build-dependencies] cc = "1.0" diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index a9ee47c80..6274d8fcb 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -1,3 +1,6 @@ +//Uncomment this for libfuzzer builds: +//#![no_main] + extern crate bitcoin; extern crate bitcoin_hashes; extern crate lightning; @@ -540,6 +543,14 @@ fn main() { } } +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + let logger: Arc = Arc::new(test_logger::TestLogger{}); + do_test(data, &logger); +}); + extern crate hex; #[cfg(test)] mod tests { -- 2.39.5