rust-lightning/fuzz/fuzz_targets/msg_update_add_htlc_target.rs
Matt Corallo 42e908883f Return a malformed HTLC message when ephemeral pubkey is garbage
This resolves a spec-compliance bug with BOLT 4 where we simply
failed to deserialize the message and thus could never return an
HTLC failure message. However, note that BOLT 4 incorrectly hints
that a non-malformed message should be used ("...MUST report a
route failure to the origin node") which we cannot do as we cannot
derive a SharedSecret to encrypt a regular update_fail_htlc message
2018-08-27 11:47:11 -04:00

45 lines
811 B
Rust

extern crate lightning;
use lightning::ln::msgs;
use lightning::util::reset_rng_state;
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
if let Ok(msg) = msgs::UpdateAddHTLC::decode(data){
let enc = msg.encode();
assert_eq!(&data[0..85], &enc[0..85]);
assert_eq!(&data[85+33..enc.len()], &enc[85+33..]);
}
}
#[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());
}
}