]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fix message targets to not have an internal loop
authorMatt Corallo <git@bluematt.me>
Sun, 17 Jun 2018 03:11:37 +0000 (23:11 -0400)
committerMatt Corallo <git@bluematt.me>
Sun, 17 Jun 2018 03:26:56 +0000 (23:26 -0400)
16 files changed:
fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs
fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs
fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs
fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs
fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs
fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs
fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs
fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs
fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs
fuzz/fuzz_targets/msg_targets/msg_target_template.txt
fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs
fuzz/fuzz_targets/msg_targets/utils.rs

index 146358cb8cd349f44fc55d54d1feb499f9050679..a0e9cc4efb511240f632b2e1c260ebc288d4c792 100644 (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")]
index 1c32ab6ed116070e6aa85a3b52d6695b8db1e84c..621ffe2b18d70bfa6157a35f0ffc33c6c25d45df 100644 (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")]
index 494ce54c2c9394567c93089d5cbf3366eae2ff13..e73696c8d3801e9805d32ee28ca8fd3499cb29a5 100644 (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")]
index 2420e921ecff8775ac9a93f0bcd298bfd0d306eb..f7d1a58a5e930ef3c3cfb4593754a46b877f837c 100644 (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")]
index edf7ba9eb96239d0bc387a6fe85427bebb0045ff..00fdef3f82d572fd139ccad7f4025643d5a55368 100644 (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")]
index a17b9ba8077ede56bc574e32aaad13af53076d7d..9b66c88fefeae67aa35710114923176e0da7d7f6 100644 (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")]
index f4c8803cb3894742a4c1aae23b1d478efb2841dc..8d7664f8ac5bfc7cfb07b1f0441d6469766f92e1 100644 (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")]
index 725903af730045369768b238174a782076def76d..de7e9314118b265612590051bf7358c29818e0ef 100644 (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")]
index 855b4aa7f41c52b33eac96e05132befcaebae2dc..57e245676d935763742607fee194a338c5d616b4 100644 (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")]
index 05abd72367e0a7b57e4196698f55ff1a5a3fa5d3..55a9761c9d611127c261b68bba4cd72ec0243a25 100644 (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")]
index a6489cb41ad99d17fb109e1e9e6ebf789a684e27..2a2c80701cb98232ba054a1452454178746dd41f 100644 (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")]
index d389b36ca6a6f9bbadd6c86b7d03518dbd05a663..aca62f7bb4bf9dd343f80b38f3f5596e939a97ad 100644 (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")]
index 4ea37a5b1d9302689a9c56c6b12fa03fe445171d..e91bb3bdfd1a832d3a581df22a26622f2e57c06c 100644 (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")]
index 4025d94908ba1846a71123c33d1e1a9772acf473..e7488306b16e98a9961371901b295237ea01bae8 100644 (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")]
index edddfb54cbab41d96673cdce097adb5d999241d4..cd449908a1736faad13884d41c8cd516fd74ecd4 100644 (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")]
index cfe5a10e9b0896e91a861052e13f458c6abe79a8..4d355585da5d18d42dceaabdd8188953e038c3f8 100644 (file)
@@ -1,50 +1,13 @@
 #![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) => {
-               {
-                       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,
-                       }
-               }
-       }
-}
-
-#[macro_export]
-macro_rules! get_slice {
-       ($data: ident, $read_pos: ident, $len: expr) => {
+       ($MsgType: path, $data: ident) => {
                {
-                       let slice_len = $len as usize;
-                       if $data.len() < $read_pos + slice_len {
-                               return;
+                       if let Ok(msg) = <$MsgType as MsgDecodable>::decode($data){
+                               let enc = msg.encode();
+                               assert_eq!(&$data[..enc.len()], &enc[..]);
                        }
-                       $read_pos += slice_len;
-                       &$data[$read_pos - slice_len..$read_pos]
                }
        }
 }