Skip to content

Commit a3973d4

Browse files
committed
Adding fuzzers for gossip_queries messages
This commit adds ser/deser fuzzers for five new structs in ln::msgs used for gossip_queries.
1 parent ec344b3 commit a3973d4

14 files changed

+665
-0
lines changed

fuzz/src/bin/gen_target.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ GEN_TEST msg_update_fulfill_htlc msg_targets::
3232

3333
GEN_TEST msg_channel_announcement msg_targets::
3434
GEN_TEST msg_node_announcement msg_targets::
35+
GEN_TEST msg_query_short_channel_ids msg_targets::
36+
GEN_TEST msg_reply_short_channel_ids_end msg_targets::
37+
GEN_TEST msg_query_channel_range msg_targets::
38+
GEN_TEST msg_reply_channel_range msg_targets::
39+
GEN_TEST msg_gossip_timestamp_filter msg_targets::
3540

3641
GEN_TEST msg_update_add_htlc msg_targets::
3742
GEN_TEST msg_error_message msg_targets::
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
extern crate lightning_fuzz;
16+
use lightning_fuzz::msg_targets::msg_gossip_timestamp_filter::*;
17+
18+
#[cfg(feature = "afl")]
19+
#[macro_use] extern crate afl;
20+
#[cfg(feature = "afl")]
21+
fn main() {
22+
fuzz!(|data| {
23+
msg_gossip_timestamp_filter_run(data.as_ptr(), data.len());
24+
});
25+
}
26+
27+
#[cfg(feature = "honggfuzz")]
28+
#[macro_use] extern crate honggfuzz;
29+
#[cfg(feature = "honggfuzz")]
30+
fn main() {
31+
loop {
32+
fuzz!(|data| {
33+
msg_gossip_timestamp_filter_run(data.as_ptr(), data.len());
34+
});
35+
}
36+
}
37+
38+
#[cfg(feature = "libfuzzer_fuzz")]
39+
#[macro_use] extern crate libfuzzer_sys;
40+
#[cfg(feature = "libfuzzer_fuzz")]
41+
fuzz_target!(|data: &[u8]| {
42+
msg_gossip_timestamp_filter_run(data.as_ptr(), data.len());
43+
});
44+
45+
#[cfg(feature = "stdin_fuzz")]
46+
fn main() {
47+
use std::io::Read;
48+
49+
let mut data = Vec::with_capacity(8192);
50+
std::io::stdin().read_to_end(&mut data).unwrap();
51+
msg_gossip_timestamp_filter_run(data.as_ptr(), data.len());
52+
}
53+
54+
#[test]
55+
fn run_test_cases() {
56+
use std::fs;
57+
use std::io::Read;
58+
use lightning_fuzz::utils::test_logger::StringBuffer;
59+
60+
use std::sync::{atomic, Arc};
61+
{
62+
let data: Vec<u8> = vec![0];
63+
msg_gossip_timestamp_filter_run(data.as_ptr(), data.len());
64+
}
65+
let mut threads = Vec::new();
66+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
67+
if let Ok(tests) = fs::read_dir("test_cases/msg_gossip_timestamp_filter") {
68+
for test in tests {
69+
let mut data: Vec<u8> = Vec::new();
70+
let path = test.unwrap().path();
71+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
72+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
73+
74+
let thread_count_ref = Arc::clone(&threads_running);
75+
let main_thread_ref = std::thread::current();
76+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
77+
std::thread::spawn(move || {
78+
let string_logger = StringBuffer::new();
79+
80+
let panic_logger = string_logger.clone();
81+
let res = if ::std::panic::catch_unwind(move || {
82+
msg_gossip_timestamp_filter_test(&data, panic_logger);
83+
}).is_err() {
84+
Some(string_logger.into_string())
85+
} else { None };
86+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
87+
main_thread_ref.unpark();
88+
res
89+
})
90+
));
91+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
92+
std::thread::park();
93+
}
94+
}
95+
}
96+
for (test, thread) in threads.drain(..) {
97+
if let Some(output) = thread.join().unwrap() {
98+
println!("Output of {}:\n{}", test, output);
99+
panic!();
100+
}
101+
}
102+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
extern crate lightning_fuzz;
16+
use lightning_fuzz::msg_targets::msg_query_channel_range::*;
17+
18+
#[cfg(feature = "afl")]
19+
#[macro_use] extern crate afl;
20+
#[cfg(feature = "afl")]
21+
fn main() {
22+
fuzz!(|data| {
23+
msg_query_channel_range_run(data.as_ptr(), data.len());
24+
});
25+
}
26+
27+
#[cfg(feature = "honggfuzz")]
28+
#[macro_use] extern crate honggfuzz;
29+
#[cfg(feature = "honggfuzz")]
30+
fn main() {
31+
loop {
32+
fuzz!(|data| {
33+
msg_query_channel_range_run(data.as_ptr(), data.len());
34+
});
35+
}
36+
}
37+
38+
#[cfg(feature = "libfuzzer_fuzz")]
39+
#[macro_use] extern crate libfuzzer_sys;
40+
#[cfg(feature = "libfuzzer_fuzz")]
41+
fuzz_target!(|data: &[u8]| {
42+
msg_query_channel_range_run(data.as_ptr(), data.len());
43+
});
44+
45+
#[cfg(feature = "stdin_fuzz")]
46+
fn main() {
47+
use std::io::Read;
48+
49+
let mut data = Vec::with_capacity(8192);
50+
std::io::stdin().read_to_end(&mut data).unwrap();
51+
msg_query_channel_range_run(data.as_ptr(), data.len());
52+
}
53+
54+
#[test]
55+
fn run_test_cases() {
56+
use std::fs;
57+
use std::io::Read;
58+
use lightning_fuzz::utils::test_logger::StringBuffer;
59+
60+
use std::sync::{atomic, Arc};
61+
{
62+
let data: Vec<u8> = vec![0];
63+
msg_query_channel_range_run(data.as_ptr(), data.len());
64+
}
65+
let mut threads = Vec::new();
66+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
67+
if let Ok(tests) = fs::read_dir("test_cases/msg_query_channel_range") {
68+
for test in tests {
69+
let mut data: Vec<u8> = Vec::new();
70+
let path = test.unwrap().path();
71+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
72+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
73+
74+
let thread_count_ref = Arc::clone(&threads_running);
75+
let main_thread_ref = std::thread::current();
76+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
77+
std::thread::spawn(move || {
78+
let string_logger = StringBuffer::new();
79+
80+
let panic_logger = string_logger.clone();
81+
let res = if ::std::panic::catch_unwind(move || {
82+
msg_query_channel_range_test(&data, panic_logger);
83+
}).is_err() {
84+
Some(string_logger.into_string())
85+
} else { None };
86+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
87+
main_thread_ref.unpark();
88+
res
89+
})
90+
));
91+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
92+
std::thread::park();
93+
}
94+
}
95+
}
96+
for (test, thread) in threads.drain(..) {
97+
if let Some(output) = thread.join().unwrap() {
98+
println!("Output of {}:\n{}", test, output);
99+
panic!();
100+
}
101+
}
102+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
extern crate lightning_fuzz;
16+
use lightning_fuzz::msg_targets::msg_query_short_channel_ids::*;
17+
18+
#[cfg(feature = "afl")]
19+
#[macro_use] extern crate afl;
20+
#[cfg(feature = "afl")]
21+
fn main() {
22+
fuzz!(|data| {
23+
msg_query_short_channel_ids_run(data.as_ptr(), data.len());
24+
});
25+
}
26+
27+
#[cfg(feature = "honggfuzz")]
28+
#[macro_use] extern crate honggfuzz;
29+
#[cfg(feature = "honggfuzz")]
30+
fn main() {
31+
loop {
32+
fuzz!(|data| {
33+
msg_query_short_channel_ids_run(data.as_ptr(), data.len());
34+
});
35+
}
36+
}
37+
38+
#[cfg(feature = "libfuzzer_fuzz")]
39+
#[macro_use] extern crate libfuzzer_sys;
40+
#[cfg(feature = "libfuzzer_fuzz")]
41+
fuzz_target!(|data: &[u8]| {
42+
msg_query_short_channel_ids_run(data.as_ptr(), data.len());
43+
});
44+
45+
#[cfg(feature = "stdin_fuzz")]
46+
fn main() {
47+
use std::io::Read;
48+
49+
let mut data = Vec::with_capacity(8192);
50+
std::io::stdin().read_to_end(&mut data).unwrap();
51+
msg_query_short_channel_ids_run(data.as_ptr(), data.len());
52+
}
53+
54+
#[test]
55+
fn run_test_cases() {
56+
use std::fs;
57+
use std::io::Read;
58+
use lightning_fuzz::utils::test_logger::StringBuffer;
59+
60+
use std::sync::{atomic, Arc};
61+
{
62+
let data: Vec<u8> = vec![0];
63+
msg_query_short_channel_ids_run(data.as_ptr(), data.len());
64+
}
65+
let mut threads = Vec::new();
66+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
67+
if let Ok(tests) = fs::read_dir("test_cases/msg_query_short_channel_ids") {
68+
for test in tests {
69+
let mut data: Vec<u8> = Vec::new();
70+
let path = test.unwrap().path();
71+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
72+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
73+
74+
let thread_count_ref = Arc::clone(&threads_running);
75+
let main_thread_ref = std::thread::current();
76+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
77+
std::thread::spawn(move || {
78+
let string_logger = StringBuffer::new();
79+
80+
let panic_logger = string_logger.clone();
81+
let res = if ::std::panic::catch_unwind(move || {
82+
msg_query_short_channel_ids_test(&data, panic_logger);
83+
}).is_err() {
84+
Some(string_logger.into_string())
85+
} else { None };
86+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
87+
main_thread_ref.unpark();
88+
res
89+
})
90+
));
91+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
92+
std::thread::park();
93+
}
94+
}
95+
}
96+
for (test, thread) in threads.drain(..) {
97+
if let Some(output) = thread.join().unwrap() {
98+
println!("Output of {}:\n{}", test, output);
99+
panic!();
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)