add fuzz target for messages
[rust-lightning] / fuzz / fuzz_targets / msg_targets / msg_shutdown_target.rs
1 extern crate lightning;
2
3 use lightning::ln::msgs;
4 use lightning::util::reset_rng_state;
5
6 use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
7
8 mod utils;
9 use utils::slice_to_be16;
10
11 #[inline]
12 pub fn do_test(data: &[u8]) {
13         reset_rng_state();
14         let mut read_pos = 0;
15         loop {
16                 test_msg!(msgs::Shutdown, data, read_pos);
17         }
18 }
19
20 #[cfg(feature = "afl")]
21 extern crate afl;
22 #[cfg(feature = "afl")]
23 fn main() {
24         afl::read_stdio_bytes(|data| {
25                 do_test(&data);
26         });
27 }
28
29 #[cfg(feature = "honggfuzz")]
30 #[macro_use] extern crate honggfuzz;
31 #[cfg(feature = "honggfuzz")]
32 fn main() {
33         loop {
34                 fuzz!(|data| {
35                         do_test(data);
36                 });
37         }
38 }
39
40 #[cfg(test)]
41 mod tests {
42         use utils::extend_vec_from_hex;
43         #[test]
44         fn duplicate_crash() {
45                 let mut a = Vec::new();
46                 extend_vec_from_hex("00", &mut a);
47                 super::do_test(&a);
48         }
49 }