X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=fuzz%2Ffuzz_targets%2Fchannel_target.rs;h=5cf0783c58bc7201155ac8234e0dd51b4f43a14e;hb=4e4fa56e2b52971271ccddf56e8195d96b1c69ba;hp=7b3b7df1ce2ec3ddcc039212e92352bddef8b246;hpb=8c709d1b6f8bd03d2982b9f94f936a61522f6e4b;p=rust-lightning diff --git a/fuzz/fuzz_targets/channel_target.rs b/fuzz/fuzz_targets/channel_target.rs index 7b3b7df1..5cf0783c 100644 --- a/fuzz/fuzz_targets/channel_target.rs +++ b/fuzz/fuzz_targets/channel_target.rs @@ -8,13 +8,14 @@ use bitcoin::util::hash::Sha256dHash; use bitcoin::network::serialize::{serialize, BitcoinHash}; use lightning::ln::channel::{Channel, ChannelKeys}; -use lightning::ln::channelmanager::{HTLCFailReason, PendingHTLCStatus}; +use lightning::ln::channelmanager::{HTLCFailReason, HTLCSource, PendingHTLCStatus}; use lightning::ln::msgs; -use lightning::ln::msgs::{MsgDecodable, ErrorAction}; +use lightning::ln::msgs::{ErrorAction}; use lightning::chain::chaininterface::{FeeEstimator, ConfirmationTarget}; use lightning::chain::transaction::OutPoint; use lightning::util::reset_rng_state; use lightning::util::logger::Logger; +use lightning::util::ser::{Readable, Reader}; mod utils; @@ -119,8 +120,9 @@ pub fn do_test(data: &[u8]) { } macro_rules! decode_msg { - ($MsgType: path, $len: expr) => { - match <($MsgType)>::decode(get_slice!($len)) { + ($MsgType: path, $len: expr) => {{ + let mut reader = Reader::new(::std::io::Cursor::new(get_slice!($len))); + match <($MsgType)>::read(&mut reader) { Ok(msg) => msg, Err(e) => match e { msgs::DecodeError::UnknownRealmByte => return, @@ -131,9 +133,11 @@ pub fn do_test(data: &[u8]) { msgs::DecodeError::ExtraAddressesPerType => return, msgs::DecodeError::BadLengthDescriptor => return, msgs::DecodeError::ShortRead => panic!("We picked the length..."), + msgs::DecodeError::InvalidValue => panic!("Should not happen with p2p message decoding"), + msgs::DecodeError::Io(e) => panic!(format!("{}", e)), } } - } + }} } macro_rules! decode_msg_with_len16 { @@ -143,19 +147,7 @@ pub fn do_test(data: &[u8]) { Some(slice) => slice, None => return, }[$begin_len..$begin_len + 2]); - match <($MsgType)>::decode(get_slice!($begin_len as usize + 2 + (extra_len as usize)*$factor)) { - Ok(msg) => msg, - Err(e) => match e { - msgs::DecodeError::UnknownRealmByte => return, - msgs::DecodeError::UnknownRequiredFeature => return, - msgs::DecodeError::BadPublicKey => return, - msgs::DecodeError::BadSignature => return, - msgs::DecodeError::BadText => return, - msgs::DecodeError::ExtraAddressesPerType => return, - msgs::DecodeError::BadLengthDescriptor => return, - msgs::DecodeError::ShortRead => panic!("We picked the length..."), - } - } + decode_msg!($MsgType, $begin_len as usize + 2 + (extra_len as usize)*$factor) } } } @@ -205,7 +197,7 @@ pub fn do_test(data: &[u8]) { Ok(chan) => chan, Err(_) => return, }; - chan.get_open_channel(Sha256dHash::from(get_slice!(32)), &fee_est).unwrap(); + chan.get_open_channel(Sha256dHash::from(get_slice!(32)), &fee_est); let accept_chan = if get_slice!(1)[0] == 0 { decode_msg_with_len16!(msgs::AcceptChannel, 270, 1) } else { @@ -269,7 +261,7 @@ pub fn do_test(data: &[u8]) { loop { match get_slice!(1)[0] { 0 => { - test_err!(channel.send_htlc(slice_to_be64(get_slice!(8)), [42; 32], slice_to_be32(get_slice!(4)), msgs::OnionPacket { + test_err!(channel.send_htlc(slice_to_be64(get_slice!(8)), [42; 32], slice_to_be32(get_slice!(4)), HTLCSource::dummy(), msgs::OnionPacket { version: get_slice!(1)[0], public_key: PublicKey::from_slice(&secp_ctx, get_slice!(33)), hop_data: [0; 20*65],