Skip to content

Commit d8474c9

Browse files
authored
Merge pull request #30 from TheBlueMatt/master
Working initial routing sync from lnd node
2 parents 3cf262c + 4de3cfe commit d8474c9

22 files changed

+275
-133
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_ping_target.rs"
49+
50+
[[bin]]
51+
name = "msg_pong_target"
52+
path = "fuzz_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_ping_target.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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::util::reset_rng_state;
7+
8+
use lightning::ln::msgs::{MsgEncodable, MsgDecodable, Ping};
9+
10+
#[inline]
11+
pub fn do_test(data: &[u8]) {
12+
reset_rng_state();
13+
if let Ok(msg) = Ping::decode(data) {
14+
let _ = msg.encode();
15+
}
16+
}
17+
18+
#[cfg(feature = "afl")]
19+
extern crate afl;
20+
#[cfg(feature = "afl")]
21+
fn main() {
22+
afl::read_stdio_bytes(|data| {
23+
do_test(&data);
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+
do_test(data);
34+
});
35+
}
36+
}
37+
38+
#[cfg(test)]
39+
mod tests {
40+
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
41+
let mut b = 0;
42+
for (idx, c) in hex.as_bytes().iter().enumerate() {
43+
b <<= 4;
44+
match *c {
45+
b'A'...b'F' => b |= c - b'A' + 10,
46+
b'a'...b'f' => b |= c - b'a' + 10,
47+
b'0'...b'9' => b |= c - b'0',
48+
_ => panic!("Bad hex"),
49+
}
50+
if (idx & 1) == 1 {
51+
out.push(b);
52+
b = 0;
53+
}
54+
}
55+
}
56+
57+
#[test]
58+
fn duplicate_crash() {
59+
let mut a = Vec::new();
60+
extend_vec_from_hex("00", &mut a);
61+
super::do_test(&a);
62+
}
63+
}

fuzz/fuzz_targets/msg_pong_target.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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::util::reset_rng_state;
7+
8+
use lightning::ln::msgs::{MsgEncodable, MsgDecodable, Pong};
9+
10+
#[inline]
11+
pub fn do_test(data: &[u8]) {
12+
reset_rng_state();
13+
if let Ok(msg) = Pong::decode(data) {
14+
let _ = msg.encode();
15+
}
16+
}
17+
18+
#[cfg(feature = "afl")]
19+
extern crate afl;
20+
#[cfg(feature = "afl")]
21+
fn main() {
22+
afl::read_stdio_bytes(|data| {
23+
do_test(&data);
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+
do_test(data);
34+
});
35+
}
36+
}
37+
38+
#[cfg(test)]
39+
mod tests {
40+
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
41+
let mut b = 0;
42+
for (idx, c) in hex.as_bytes().iter().enumerate() {
43+
b <<= 4;
44+
match *c {
45+
b'A'...b'F' => b |= c - b'A' + 10,
46+
b'a'...b'f' => b |= c - b'a' + 10,
47+
b'0'...b'9' => b |= c - b'0',
48+
_ => panic!("Bad hex"),
49+
}
50+
if (idx & 1) == 1 {
51+
out.push(b);
52+
b = 0;
53+
}
54+
}
55+
}
56+
57+
#[test]
58+
fn duplicate_crash() {
59+
let mut a = Vec::new();
60+
extend_vec_from_hex("00", &mut a);
61+
super::do_test(&a);
62+
}
63+
}

fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::AcceptChannel, data, read_pos);
20-
}
16+
test_msg!(msgs::AcceptChannel, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::ClosingSigned, data, read_pos);
20-
}
16+
test_msg!(msgs::ClosingSigned, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::CommitmentSigned, data, read_pos);
20-
}
16+
test_msg!(msgs::CommitmentSigned, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::FundingCreated, data, read_pos);
20-
}
16+
test_msg!(msgs::FundingCreated, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::FundingLocked, data, read_pos);
20-
}
16+
test_msg!(msgs::FundingLocked, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::FundingSigned, data, read_pos);
20-
}
16+
test_msg!(msgs::FundingSigned, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::OpenChannel, data, read_pos);
20-
}
16+
test_msg!(msgs::OpenChannel, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::RevokeAndACK, data, read_pos);
20-
}
16+
test_msg!(msgs::RevokeAndACK, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::Shutdown, data, read_pos);
20-
}
16+
test_msg!(msgs::Shutdown, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_target_template.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::MSG_TARGET, data, read_pos);
20-
}
16+
test_msg!(msgs::MSG_TARGET, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::UpdateAddHTLC, data, read_pos);
20-
}
16+
test_msg!(msgs::UpdateAddHTLC, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::UpdateFailHTLC, data, read_pos);
20-
}
16+
test_msg!(msgs::UpdateFailHTLC, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::UpdateFailMalformedHTLC, data, read_pos);
20-
}
16+
test_msg!(msgs::UpdateFailMalformedHTLC, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::UpdateFee, data, read_pos);
20-
}
16+
test_msg!(msgs::UpdateFee, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
99
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
1010

1111
mod utils;
12-
use utils::slice_to_be16;
1312

1413
#[inline]
1514
pub fn do_test(data: &[u8]) {
1615
reset_rng_state();
17-
let mut read_pos = 0;
18-
loop {
19-
test_msg!(msgs::UpdateFulfillHTLC, data, read_pos);
20-
}
16+
test_msg!(msgs::UpdateFulfillHTLC, data);
2117
}
2218

2319
#[cfg(feature = "afl")]

0 commit comments

Comments
 (0)