Fix message targets to not have an internal loop

This commit is contained in:
Matt Corallo 2018-06-16 23:11:37 -04:00
parent a73dea7722
commit 4de3cfe665
16 changed files with 19 additions and 116 deletions

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::AcceptChannel, data, read_pos);
}
test_msg!(msgs::AcceptChannel, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::ClosingSigned, data, read_pos);
}
test_msg!(msgs::ClosingSigned, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::CommitmentSigned, data, read_pos);
}
test_msg!(msgs::CommitmentSigned, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::FundingCreated, data, read_pos);
}
test_msg!(msgs::FundingCreated, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::FundingLocked, data, read_pos);
}
test_msg!(msgs::FundingLocked, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::FundingSigned, data, read_pos);
}
test_msg!(msgs::FundingSigned, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::OpenChannel, data, read_pos);
}
test_msg!(msgs::OpenChannel, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::RevokeAndACK, data, read_pos);
}
test_msg!(msgs::RevokeAndACK, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::Shutdown, data, read_pos);
}
test_msg!(msgs::Shutdown, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::MSG_TARGET, data, read_pos);
}
test_msg!(msgs::MSG_TARGET, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::UpdateAddHTLC, data, read_pos);
}
test_msg!(msgs::UpdateAddHTLC, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::UpdateFailHTLC, data, read_pos);
}
test_msg!(msgs::UpdateFailHTLC, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::UpdateFailMalformedHTLC, data, read_pos);
}
test_msg!(msgs::UpdateFailMalformedHTLC, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::UpdateFee, data, read_pos);
}
test_msg!(msgs::UpdateFee, data);
}
#[cfg(feature = "afl")]

View file

@ -9,15 +9,11 @@ use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
let mut read_pos = 0;
loop {
test_msg!(msgs::UpdateFulfillHTLC, data, read_pos);
}
test_msg!(msgs::UpdateFulfillHTLC, data);
}
#[cfg(feature = "afl")]

View file

@ -1,54 +1,17 @@
#![macro_use]
#[allow(dead_code)]
#[inline]
pub fn slice_to_be16(v: &[u8]) -> u16 {
((v[0] as u16) << 8*1) |
((v[1] as u16) << 8*0)
}
#[macro_export]
macro_rules! test_msg {
($MsgType: path, $data: ident, $read_pos: ident) => {
($MsgType: path, $data: ident) => {
{
let len = slice_to_be16(get_slice!($data, $read_pos, 2));
let raw = get_slice!($data, $read_pos, len);
let cb = decode_msg!($MsgType, raw).encode();
assert_eq!(&raw[..cb.len()], &cb[..]);
}
}
}
#[macro_export]
macro_rules! decode_msg {
($MsgType: path, $data: expr) => {
match <($MsgType)>::decode($data) {
Ok(msg) => msg,
Err(e) => match e {
msgs::DecodeError::UnknownRealmByte => return,
msgs::DecodeError::BadPublicKey => return,
msgs::DecodeError::BadSignature => return,
msgs::DecodeError::ExtraAddressesPerType => return,
msgs::DecodeError::WrongLength => return,
if let Ok(msg) = <$MsgType as MsgDecodable>::decode($data){
let enc = msg.encode();
assert_eq!(&$data[..enc.len()], &enc[..]);
}
}
}
}
#[macro_export]
macro_rules! get_slice {
($data: ident, $read_pos: ident, $len: expr) => {
{
let slice_len = $len as usize;
if $data.len() < $read_pos + slice_len {
return;
}
$read_pos += slice_len;
&$data[$read_pos - slice_len..$read_pos]
}
}
}
#[allow(dead_code)]
#[cfg(test)]
pub fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {