mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-04 10:58:11 +01:00
add script to generate msg test target
This commit is contained in:
parent
7822af8bd1
commit
e2ff3393ea
2 changed files with 54 additions and 0 deletions
5
fuzz/fuzz_targets/msg_targets/gen_target.sh
Normal file
5
fuzz/fuzz_targets/msg_targets/gen_target.sh
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
for target in CommitmentSigned FundingCreated FundingLocked FundingSigned OpenChannel RevokeAndACK Shutdown UpdateAddHTLC UpdateFailHTLC UpdateFailMalformedHTLC UpdateFee UpdateFulfillHTLC AcceptChannel ClosingSigned; do
|
||||||
|
tn=$(echo $target | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\L\2/g')
|
||||||
|
fn=msg_$(echo $tn | tr '[:upper:]' '[:lower:]')_target.rs
|
||||||
|
cat msg_target_template.txt | sed s/MSG_TARGET/$target/ > $fn
|
||||||
|
done
|
49
fuzz/fuzz_targets/msg_targets/msg_target_template.txt
Normal file
49
fuzz/fuzz_targets/msg_targets/msg_target_template.txt
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
extern crate lightning;
|
||||||
|
|
||||||
|
use lightning::ln::msgs;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "afl")]
|
||||||
|
extern crate afl;
|
||||||
|
#[cfg(feature = "afl")]
|
||||||
|
fn main() {
|
||||||
|
afl::read_stdio_bytes(|data| {
|
||||||
|
do_test(&data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "honggfuzz")]
|
||||||
|
#[macro_use] extern crate honggfuzz;
|
||||||
|
#[cfg(feature = "honggfuzz")]
|
||||||
|
fn main() {
|
||||||
|
loop {
|
||||||
|
fuzz!(|data| {
|
||||||
|
do_test(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use utils::extend_vec_from_hex;
|
||||||
|
#[test]
|
||||||
|
fn duplicate_crash() {
|
||||||
|
let mut a = Vec::new();
|
||||||
|
extend_vec_from_hex("00", &mut a);
|
||||||
|
super::do_test(&a);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue