# message fuzz targets
[[bin]]
name = "msg_ping_target"
-path = "fuzz_targets/msg_ping_target.rs"
+path = "fuzz_targets/msg_targets/msg_ping_target.rs"
[[bin]]
name = "msg_pong_target"
-path = "fuzz_targets/msg_pong_target.rs"
+path = "fuzz_targets/msg_targets/msg_pong_target.rs"
[[bin]]
name = "msg_error_message_target"
+++ /dev/null
-// This file is auto-generated by gen_target.sh based on msg_target_template.txt
-// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
-
-extern crate lightning;
-
-use lightning::util::reset_rng_state;
-
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable, Ping};
-
-#[inline]
-pub fn do_test(data: &[u8]) {
- reset_rng_state();
- if let Ok(msg) = Ping::decode(data) {
- let _ = msg.encode();
- }
-}
-
-#[cfg(feature = "afl")]
-#[macro_use] extern crate afl;
-#[cfg(feature = "afl")]
-fn main() {
- fuzz!(|data| {
- do_test(data);
- });
-}
-
-#[cfg(feature = "honggfuzz")]
-#[macro_use] extern crate honggfuzz;
-#[cfg(feature = "honggfuzz")]
-fn main() {
- loop {
- fuzz!(|data| {
- do_test(data);
- });
- }
-}
-
-extern crate hex;
-#[cfg(test)]
-mod tests {
- #[test]
- fn duplicate_crash() {
- super::do_test(&::hex::decode("00").unwrap());
- }
-}
+++ /dev/null
-// This file is auto-generated by gen_target.sh based on msg_target_template.txt
-// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
-
-extern crate lightning;
-
-use lightning::util::reset_rng_state;
-
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable, Pong};
-
-#[inline]
-pub fn do_test(data: &[u8]) {
- reset_rng_state();
- if let Ok(msg) = Pong::decode(data) {
- let _ = msg.encode();
- }
-}
-
-#[cfg(feature = "afl")]
-#[macro_use] extern crate afl;
-#[cfg(feature = "afl")]
-fn main() {
- fuzz!(|data| {
- do_test(data);
- });
-}
-
-#[cfg(feature = "honggfuzz")]
-#[macro_use] extern crate honggfuzz;
-#[cfg(feature = "honggfuzz")]
-fn main() {
- loop {
- fuzz!(|data| {
- do_test(data);
- });
- }
-}
-
-extern crate hex;
-#[cfg(test)]
-mod tests {
- #[test]
- fn duplicate_crash() {
- super::do_test(&::hex::decode("00").unwrap());
- }
-}
GEN_TEST UpdateAddHTLC test_msg_hole ", 85, 33"
GEN_TEST ErrorMessage test_msg_hole ", 32, 2"
GEN_TEST OnionHopData test_msg_hole ", 1+8+8+4, 12"
+
+GEN_TEST Ping test_msg_simple ""
+GEN_TEST Pong test_msg_simple ""
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
--- /dev/null
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+extern crate lightning;
+
+use lightning::ln::msgs;
+use lightning::util::reset_rng_state;
+
+mod utils;
+
+#[inline]
+pub fn do_test(data: &[u8]) {
+ reset_rng_state();
+ test_msg_simple!(msgs::Ping, data);
+}
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+ fuzz!(|data| {
+ do_test(data);
+ });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+ loop {
+ fuzz!(|data| {
+ do_test(data);
+ });
+ }
+}
+
+extern crate hex;
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn duplicate_crash() {
+ super::do_test(&::hex::decode("00").unwrap());
+ }
+}
--- /dev/null
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+extern crate lightning;
+
+use lightning::ln::msgs;
+use lightning::util::reset_rng_state;
+
+mod utils;
+
+#[inline]
+pub fn do_test(data: &[u8]) {
+ reset_rng_state();
+ test_msg_simple!(msgs::Pong, data);
+}
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+ fuzz!(|data| {
+ do_test(data);
+ });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+ loop {
+ fuzz!(|data| {
+ do_test(data);
+ });
+ }
+}
+
+extern crate hex;
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn duplicate_crash() {
+ super::do_test(&::hex::decode("00").unwrap());
+ }
+}
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
-use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
-
mod utils;
#[inline]
macro_rules! test_msg {
($MsgType: path, $data: ident) => {
{
- if let Ok(msg) = <$MsgType as MsgDecodable>::decode($data){
- let enc = msg.encode();
- assert_eq!(&$data[..enc.len()], &enc[..]);
+ use lightning::util::ser::{Writer, Reader, Writeable, Readable};
+ let mut r = Reader::new(::std::io::Cursor::new($data));
+ if let Ok(msg) = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut r) {
+ let p = r.get_ref().position() as usize;
+ let mut w = Writer::new(::std::io::Cursor::new(vec![]));
+ msg.write(&mut w).unwrap();
+
+ let buf = w.into_inner().into_inner();
+ assert_eq!(buf.len(), p);
+ assert_eq!(&r.into_inner().into_inner()[..p], &buf[..p]);
+ }
+ }
+ }
+}
+
+#[macro_export]
+macro_rules! test_msg_simple {
+ ($MsgType: path, $data: ident) => {
+ {
+ use lightning::util::ser::{Writer, Reader, Writeable, Readable};
+ let mut r = Reader::new(::std::io::Cursor::new($data));
+ if let Ok(msg) = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut r) {
+ msg.write(&mut Writer::new(::std::io::Cursor::new(vec![]))).unwrap();
}
}
}
macro_rules! test_msg_exact {
($MsgType: path, $data: ident) => {
{
- if let Ok(msg) = <$MsgType as MsgDecodable>::decode($data){
- let enc = msg.encode();
- assert_eq!(&$data[..], &enc[..]);
+ use lightning::util::ser::{Writer, Reader, Writeable, Readable};
+ let mut r = Reader::new(::std::io::Cursor::new($data));
+ if let Ok(msg) = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut r) {
+ let mut w = Writer::new(::std::io::Cursor::new(vec![]));
+ msg.write(&mut w).unwrap();
+
+ let buf = w.into_inner().into_inner();
+ assert_eq!(&r.into_inner().into_inner()[..], &buf[..]);
}
}
}
macro_rules! test_msg_hole {
($MsgType: path, $data: ident, $hole: expr, $hole_len: expr) => {
{
- if let Ok(msg) = <$MsgType as MsgDecodable>::decode($data){
- let enc = msg.encode();
- assert_eq!(&$data[..$hole], &enc[..$hole]);
- assert_eq!(&$data[$hole + $hole_len..enc.len()], &enc[$hole + $hole_len..]);
+ use lightning::util::ser::{Writer, Reader, Writeable, Readable};
+ let mut r = Reader::new(::std::io::Cursor::new($data));
+ if let Ok(msg) = <$MsgType as Readable<::std::io::Cursor<&[u8]>>>::read(&mut r) {
+ let mut w = Writer::new(::std::io::Cursor::new(vec![]));
+ msg.write(&mut w).unwrap();
+ let p = w.get_ref().position() as usize;
+
+ let buf = w.into_inner().into_inner();
+ assert_eq!(buf.len(),p);
+ assert_eq!(&r.get_ref().get_ref()[..$hole], &buf[..$hole]);
+ assert_eq!(&r.get_ref().get_ref()[$hole+$hole_len..p], &buf[$hole+$hole_len..]);
}
}
}