mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-12 14:10:18 +01:00
Previously, in each of our fuzz tests we had a dummy test which had a hard-coded hex string which it passed into the fuzz target so that when a failing test case was found, its hex could be copied into the test and you could run cargo test to analyze the failure. However, this was somewhat unwieldy as converting large tests back and forth between hex and raw files is quite annoying. Instead, we replace each of those tests with a test in each target that looks for files in fuzz/test_cases and runs each file it finds. Since we're editing every bin target anyway, we also automate adding no_main to libfuzzer builds with #![cfg_attr].
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
// This file is auto-generated by gen_target.sh based on target_template.txt
|
|
// To modify it, modify target_template.txt and run gen_target.sh instead.
|
|
|
|
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
|
|
|
|
extern crate lightning_fuzz;
|
|
use lightning_fuzz::msg_targets::msg_funding_signed::*;
|
|
|
|
use std::fs;
|
|
use std::io::Read;
|
|
|
|
#[cfg(feature = "afl")]
|
|
#[macro_use] extern crate afl;
|
|
#[cfg(feature = "afl")]
|
|
fn main() {
|
|
fuzz!(|data| {
|
|
msg_funding_signed_run(data.as_ptr(), data.len());
|
|
});
|
|
}
|
|
|
|
#[cfg(feature = "honggfuzz")]
|
|
#[macro_use] extern crate honggfuzz;
|
|
#[cfg(feature = "honggfuzz")]
|
|
fn main() {
|
|
loop {
|
|
fuzz!(|data| {
|
|
msg_funding_signed_run(data.as_ptr(), data.len());
|
|
});
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "libfuzzer_fuzz")]
|
|
#[macro_use] extern crate libfuzzer_sys;
|
|
#[cfg(feature = "libfuzzer_fuzz")]
|
|
fuzz_target!(|data: &[u8]| {
|
|
msg_funding_signed_run(data.as_ptr(), data.len());
|
|
});
|
|
|
|
#[cfg(feature = "stdin_fuzz")]
|
|
fn main() {
|
|
let mut data = Vec::with_capacity(8192);
|
|
std::io::stdin().read_to_end(&mut data).unwrap();
|
|
msg_funding_signed_run(data.as_ptr(), data.len());
|
|
}
|
|
|
|
#[test]
|
|
fn run_test_cases() {
|
|
let mut data: Vec<u8> = vec![0];
|
|
msg_funding_signed_run(data.as_ptr(), data.len());
|
|
if let Ok(tests) = fs::read_dir("test_cases/msg_funding_signed") {
|
|
for test in tests {
|
|
data.clear();
|
|
let path = test.unwrap().path();
|
|
println!("Running test {}...", path.file_name().unwrap().to_str().unwrap());
|
|
fs::File::open(path).unwrap().read_to_end(&mut data).unwrap();
|
|
msg_funding_signed_run(data.as_ptr(), data.len());
|
|
}
|
|
}
|
|
}
|