Skip to content

Commit e14e192

Browse files
committed
Add ping/pong fuzz targets
1 parent e3effa4 commit e14e192

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

fuzz/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ name = "full_stack_target"
4343
path = "fuzz_targets/full_stack_target.rs"
4444

4545
# message fuzz targets
46+
[[bin]]
47+
name = "msg_ping_target"
48+
path = "fuzz_targets/msg_targets/msg_ping_target.rs"
49+
50+
[[bin]]
51+
name = "msg_pong_target"
52+
path = "fuzz_targets/msg_targets/msg_pong_target.rs"
53+
4654
[[bin]]
4755
name = "msg_accept_channel_target"
4856
path = "fuzz_targets/msg_targets/msg_accept_channel_target.rs"

fuzz/fuzz_targets/msg_targets/gen_target.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
for target in CommitmentSigned FundingCreated FundingLocked FundingSigned OpenChannel RevokeAndACK Shutdown UpdateAddHTLC UpdateFailHTLC UpdateFailMalformedHTLC UpdateFee UpdateFulfillHTLC AcceptChannel ClosingSigned; do
1+
for target in Ping Pong CommitmentSigned FundingCreated FundingLocked FundingSigned OpenChannel RevokeAndACK Shutdown UpdateAddHTLC UpdateFailHTLC UpdateFailMalformedHTLC UpdateFee UpdateFulfillHTLC AcceptChannel ClosingSigned; do
22
tn=$(echo $target | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\L\2/g')
33
fn=msg_$(echo $tn | tr '[:upper:]' '[:lower:]')_target.rs
44
cat msg_target_template.txt | sed s/MSG_TARGET/$target/ > $fn
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is auto-generated by gen_target.sh based on msg_target_template.txt
2+
// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
3+
4+
extern crate lightning;
5+
6+
use lightning::ln::msgs;
7+
use lightning::util::reset_rng_state;
8+
9+
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
10+
11+
mod utils;
12+
use utils::slice_to_be16;
13+
14+
#[inline]
15+
pub fn do_test(data: &[u8]) {
16+
reset_rng_state();
17+
let mut read_pos = 0;
18+
loop {
19+
test_msg!(msgs::Ping, data, read_pos);
20+
}
21+
}
22+
23+
#[cfg(feature = "afl")]
24+
extern crate afl;
25+
#[cfg(feature = "afl")]
26+
fn main() {
27+
afl::read_stdio_bytes(|data| {
28+
do_test(&data);
29+
});
30+
}
31+
32+
#[cfg(feature = "honggfuzz")]
33+
#[macro_use] extern crate honggfuzz;
34+
#[cfg(feature = "honggfuzz")]
35+
fn main() {
36+
loop {
37+
fuzz!(|data| {
38+
do_test(data);
39+
});
40+
}
41+
}
42+
43+
#[cfg(test)]
44+
mod tests {
45+
use utils::extend_vec_from_hex;
46+
#[test]
47+
fn duplicate_crash() {
48+
let mut a = Vec::new();
49+
extend_vec_from_hex("00", &mut a);
50+
super::do_test(&a);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is auto-generated by gen_target.sh based on msg_target_template.txt
2+
// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
3+
4+
extern crate lightning;
5+
6+
use lightning::ln::msgs;
7+
use lightning::util::reset_rng_state;
8+
9+
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
10+
11+
mod utils;
12+
use utils::slice_to_be16;
13+
14+
#[inline]
15+
pub fn do_test(data: &[u8]) {
16+
reset_rng_state();
17+
let mut read_pos = 0;
18+
loop {
19+
test_msg!(msgs::Pong, data, read_pos);
20+
}
21+
}
22+
23+
#[cfg(feature = "afl")]
24+
extern crate afl;
25+
#[cfg(feature = "afl")]
26+
fn main() {
27+
afl::read_stdio_bytes(|data| {
28+
do_test(&data);
29+
});
30+
}
31+
32+
#[cfg(feature = "honggfuzz")]
33+
#[macro_use] extern crate honggfuzz;
34+
#[cfg(feature = "honggfuzz")]
35+
fn main() {
36+
loop {
37+
fuzz!(|data| {
38+
do_test(data);
39+
});
40+
}
41+
}
42+
43+
#[cfg(test)]
44+
mod tests {
45+
use utils::extend_vec_from_hex;
46+
#[test]
47+
fn duplicate_crash() {
48+
let mut a = Vec::new();
49+
extend_vec_from_hex("00", &mut a);
50+
super::do_test(&a);
51+
}
52+
}

0 commit comments

Comments
 (0)