Add option to use libfuzzer sys in full_stack_target
authorMatt Corallo <git@bluematt.me>
Mon, 3 Dec 2018 18:56:44 +0000 (13:56 -0500)
committerMatt Corallo <git@bluematt.me>
Tue, 8 Jan 2019 19:04:06 +0000 (14:04 -0500)
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
fuzz/fuzz_targets/full_stack_target.rs

index c4ed4c70346d5059a7121e2840f45720ae8f8751..dbdb69d2e527413910b481298e98d91701458a4b 100644 (file)
@@ -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"
index a9ee47c806676da76e19acd1d1c7cf6dd71b3c6e..6274d8fcb70c6b6cb8c54a4aad4b133b32513495 100644 (file)
@@ -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<Logger> = Arc::new(test_logger::TestLogger{});
+       do_test(data, &logger);
+});
+
 extern crate hex;
 #[cfg(test)]
 mod tests {