From e28fd78e67b92de9f42dae3636c5dbea5e9b1f86 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 11 Dec 2019 13:18:43 -0500 Subject: [PATCH] Refactor fuzzing to be a C-callable library plus rust binaries This should help us avoid rust's at-load syscalls by calling the tests from a C program. --- fuzz/Cargo.toml | 125 +----------------- fuzz/src/bin/chanmon_consistency_target.rs | 44 ++++++ fuzz/src/bin/chanmon_deser_target.rs | 44 ++++++ fuzz/src/bin/full_stack_target.rs | 44 ++++++ fuzz/src/bin/gen_target.sh | 42 ++++++ fuzz/src/bin/msg_accept_channel_target.rs | 44 ++++++ .../bin/msg_announcement_signatures_target.rs | 44 ++++++ .../bin/msg_channel_announcement_target.rs | 44 ++++++ .../src/bin/msg_channel_reestablish_target.rs | 44 ++++++ fuzz/src/bin/msg_channel_update_target.rs | 44 ++++++ fuzz/src/bin/msg_closing_signed_target.rs | 44 ++++++ fuzz/src/bin/msg_commitment_signed_target.rs | 44 ++++++ .../msg_decoded_onion_error_packet_target.rs | 44 ++++++ fuzz/src/bin/msg_error_message_target.rs | 44 ++++++ fuzz/src/bin/msg_funding_created_target.rs | 44 ++++++ fuzz/src/bin/msg_funding_locked_target.rs | 44 ++++++ fuzz/src/bin/msg_funding_signed_target.rs | 44 ++++++ fuzz/src/bin/msg_init_target.rs | 44 ++++++ fuzz/src/bin/msg_node_announcement_target.rs | 44 ++++++ fuzz/src/bin/msg_onion_hop_data_target.rs | 44 ++++++ fuzz/src/bin/msg_open_channel_target.rs | 44 ++++++ fuzz/src/bin/msg_ping_target.rs | 44 ++++++ fuzz/src/bin/msg_pong_target.rs | 44 ++++++ fuzz/src/bin/msg_revoke_and_ack_target.rs | 44 ++++++ fuzz/src/bin/msg_shutdown_target.rs | 44 ++++++ fuzz/src/bin/msg_update_add_htlc_target.rs | 44 ++++++ fuzz/src/bin/msg_update_fail_htlc_target.rs | 44 ++++++ .../msg_update_fail_malformed_htlc_target.rs | 44 ++++++ fuzz/src/bin/msg_update_fee_target.rs | 44 ++++++ .../src/bin/msg_update_fulfill_htlc_target.rs | 44 ++++++ fuzz/src/bin/peer_crypt_target.rs | 44 ++++++ fuzz/src/bin/router_target.rs | 44 ++++++ fuzz/src/bin/target_template.txt | 44 ++++++ .../chanmon_consistency.rs} | 38 +----- .../chanmon_deser.rs} | 28 +--- .../full_stack.rs} | 43 +----- fuzz/src/lib.rs | 15 +++ .../msg_targets/gen_target.sh | 11 +- fuzz/src/msg_targets/mod.rs | 26 ++++ .../msg_targets/msg_accept_channel.rs} | 27 +--- .../msg_announcement_signatures.rs} | 27 +--- .../msg_targets/msg_channel_announcement.rs} | 27 +--- .../msg_targets/msg_channel_reestablish.rs} | 27 +--- .../msg_targets/msg_channel_update.rs} | 27 +--- .../msg_targets/msg_closing_signed.rs} | 27 +--- .../msg_targets/msg_commitment_signed.rs} | 27 +--- .../msg_decoded_onion_error_packet.rs} | 27 +--- .../msg_targets/msg_error_message.rs} | 27 +--- .../msg_targets/msg_funding_created.rs} | 27 +--- .../msg_targets/msg_funding_locked.rs} | 27 +--- .../msg_targets/msg_funding_signed.rs} | 27 +--- .../msg_targets/msg_init.rs} | 27 +--- .../msg_targets/msg_node_announcement.rs} | 27 +--- .../msg_targets/msg_onion_hop_data.rs} | 27 +--- .../msg_targets/msg_open_channel.rs} | 27 +--- .../msg_targets/msg_ping.rs} | 27 +--- .../msg_targets/msg_pong.rs} | 27 +--- .../msg_targets/msg_revoke_and_ack.rs} | 27 +--- .../msg_targets/msg_shutdown.rs} | 27 +--- .../msg_targets/msg_target_template.txt | 27 +--- .../msg_targets/msg_update_add_htlc.rs} | 27 +--- .../msg_targets/msg_update_fail_htlc.rs} | 27 +--- .../msg_update_fail_malformed_htlc.rs} | 27 +--- .../msg_targets/msg_update_fee.rs} | 27 +--- .../msg_targets/msg_update_fulfill_htlc.rs} | 27 +--- .../msg_targets/utils.rs | 0 .../peer_crypt.rs} | 26 +--- .../router_target.rs => src/router.rs} | 30 +---- fuzz/{fuzz_targets => src}/utils/mod.rs | 0 .../utils/test_logger.rs | 0 fuzz/targets.h | 31 +++++ fuzz/travis-fuzz.sh | 11 +- 72 files changed, 1619 insertions(+), 873 deletions(-) create mode 100644 fuzz/src/bin/chanmon_consistency_target.rs create mode 100644 fuzz/src/bin/chanmon_deser_target.rs create mode 100644 fuzz/src/bin/full_stack_target.rs create mode 100755 fuzz/src/bin/gen_target.sh create mode 100644 fuzz/src/bin/msg_accept_channel_target.rs create mode 100644 fuzz/src/bin/msg_announcement_signatures_target.rs create mode 100644 fuzz/src/bin/msg_channel_announcement_target.rs create mode 100644 fuzz/src/bin/msg_channel_reestablish_target.rs create mode 100644 fuzz/src/bin/msg_channel_update_target.rs create mode 100644 fuzz/src/bin/msg_closing_signed_target.rs create mode 100644 fuzz/src/bin/msg_commitment_signed_target.rs create mode 100644 fuzz/src/bin/msg_decoded_onion_error_packet_target.rs create mode 100644 fuzz/src/bin/msg_error_message_target.rs create mode 100644 fuzz/src/bin/msg_funding_created_target.rs create mode 100644 fuzz/src/bin/msg_funding_locked_target.rs create mode 100644 fuzz/src/bin/msg_funding_signed_target.rs create mode 100644 fuzz/src/bin/msg_init_target.rs create mode 100644 fuzz/src/bin/msg_node_announcement_target.rs create mode 100644 fuzz/src/bin/msg_onion_hop_data_target.rs create mode 100644 fuzz/src/bin/msg_open_channel_target.rs create mode 100644 fuzz/src/bin/msg_ping_target.rs create mode 100644 fuzz/src/bin/msg_pong_target.rs create mode 100644 fuzz/src/bin/msg_revoke_and_ack_target.rs create mode 100644 fuzz/src/bin/msg_shutdown_target.rs create mode 100644 fuzz/src/bin/msg_update_add_htlc_target.rs create mode 100644 fuzz/src/bin/msg_update_fail_htlc_target.rs create mode 100644 fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs create mode 100644 fuzz/src/bin/msg_update_fee_target.rs create mode 100644 fuzz/src/bin/msg_update_fulfill_htlc_target.rs create mode 100644 fuzz/src/bin/peer_crypt_target.rs create mode 100644 fuzz/src/bin/router_target.rs create mode 100644 fuzz/src/bin/target_template.txt rename fuzz/{fuzz_targets/chanmon_fail_consistency.rs => src/chanmon_consistency.rs} (97%) rename fuzz/{fuzz_targets/chanmon_deser_target.rs => src/chanmon_deser.rs} (77%) rename fuzz/{fuzz_targets/full_stack_target.rs => src/full_stack.rs} (98%) create mode 100644 fuzz/src/lib.rs rename fuzz/{fuzz_targets => src}/msg_targets/gen_target.sh (72%) create mode 100644 fuzz/src/msg_targets/mod.rs rename fuzz/{fuzz_targets/msg_targets/msg_accept_channel_target.rs => src/msg_targets/msg_accept_channel.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_announcement_signatures_target.rs => src/msg_targets/msg_announcement_signatures.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_channel_announcement_target.rs => src/msg_targets/msg_channel_announcement.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_channel_reestablish_target.rs => src/msg_targets/msg_channel_reestablish.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_channel_update_target.rs => src/msg_targets/msg_channel_update.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_closing_signed_target.rs => src/msg_targets/msg_closing_signed.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_commitment_signed_target.rs => src/msg_targets/msg_commitment_signed.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_decoded_onion_error_packet_target.rs => src/msg_targets/msg_decoded_onion_error_packet.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_error_message_target.rs => src/msg_targets/msg_error_message.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_funding_created_target.rs => src/msg_targets/msg_funding_created.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_funding_locked_target.rs => src/msg_targets/msg_funding_locked.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_funding_signed_target.rs => src/msg_targets/msg_funding_signed.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_init_target.rs => src/msg_targets/msg_init.rs} (50%) rename fuzz/{fuzz_targets/msg_targets/msg_node_announcement_target.rs => src/msg_targets/msg_node_announcement.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_onion_hop_data_target.rs => src/msg_targets/msg_onion_hop_data.rs} (52%) rename fuzz/{fuzz_targets/msg_targets/msg_open_channel_target.rs => src/msg_targets/msg_open_channel.rs} (50%) rename fuzz/{fuzz_targets/msg_targets/msg_ping_target.rs => src/msg_targets/msg_ping.rs} (50%) rename fuzz/{fuzz_targets/msg_targets/msg_pong_target.rs => src/msg_targets/msg_pong.rs} (50%) rename fuzz/{fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs => src/msg_targets/msg_revoke_and_ack.rs} (50%) rename fuzz/{fuzz_targets/msg_targets/msg_shutdown_target.rs => src/msg_targets/msg_shutdown.rs} (50%) rename fuzz/{fuzz_targets => src}/msg_targets/msg_target_template.txt (51%) rename fuzz/{fuzz_targets/msg_targets/msg_update_add_htlc_target.rs => src/msg_targets/msg_update_add_htlc.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs => src/msg_targets/msg_update_fail_htlc.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs => src/msg_targets/msg_update_fail_malformed_htlc.rs} (51%) rename fuzz/{fuzz_targets/msg_targets/msg_update_fee_target.rs => src/msg_targets/msg_update_fee.rs} (50%) rename fuzz/{fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs => src/msg_targets/msg_update_fulfill_htlc.rs} (51%) rename fuzz/{fuzz_targets => src}/msg_targets/utils.rs (100%) rename fuzz/{fuzz_targets/peer_crypt_target.rs => src/peer_crypt.rs} (84%) rename fuzz/{fuzz_targets/router_target.rs => src/router.rs} (94%) rename fuzz/{fuzz_targets => src}/utils/mod.rs (100%) rename fuzz/{fuzz_targets => src}/utils/test_logger.rs (100%) create mode 100644 fuzz/targets.h diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 96699a7db..22a6e2156 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -14,6 +14,7 @@ cargo-fuzz = true afl_fuzz = ["afl"] honggfuzz_fuzz = ["honggfuzz"] libfuzzer_fuzz = ["libfuzzer-sys"] +stdin_fuzz = [] [dependencies] afl = { version = "0.4", optional = true } @@ -36,123 +37,7 @@ members = ["."] lto = true codegen-units = 1 -[[bin]] -name = "peer_crypt_target" -path = "fuzz_targets/peer_crypt_target.rs" - -[[bin]] -name = "full_stack_target" -path = "fuzz_targets/full_stack_target.rs" - -[[bin]] -name = "chanmon_fail_consistency" -path = "fuzz_targets/chanmon_fail_consistency.rs" - -[[bin]] -name = "router_target" -path = "fuzz_targets/router_target.rs" - -[[bin]] -name = "chanmon_deser_target" -path = "fuzz_targets/chanmon_deser_target.rs" - -# message fuzz targets -[[bin]] -name = "msg_ping_target" -path = "fuzz_targets/msg_targets/msg_ping_target.rs" - -[[bin]] -name = "msg_pong_target" -path = "fuzz_targets/msg_targets/msg_pong_target.rs" - -[[bin]] -name = "msg_error_message_target" -path = "fuzz_targets/msg_targets/msg_error_message_target.rs" - -[[bin]] -name = "msg_update_add_htlc_target" -path = "fuzz_targets/msg_targets/msg_update_add_htlc_target.rs" - -[[bin]] -name = "msg_accept_channel_target" -path = "fuzz_targets/msg_targets/msg_accept_channel_target.rs" - -[[bin]] -name = "msg_closing_signed_target" -path = "fuzz_targets/msg_targets/msg_closing_signed_target.rs" - -[[bin]] -name = "msg_commitment_signed_target" -path = "fuzz_targets/msg_targets/msg_commitment_signed_target.rs" - -[[bin]] -name = "msg_funding_created_target" -path = "fuzz_targets/msg_targets/msg_funding_created_target.rs" - -[[bin]] -name = "msg_funding_locked_target" -path = "fuzz_targets/msg_targets/msg_funding_locked_target.rs" - -[[bin]] -name = "msg_funding_signed_target" -path = "fuzz_targets/msg_targets/msg_funding_signed_target.rs" - -[[bin]] -name = "msg_open_channel_target" -path = "fuzz_targets/msg_targets/msg_open_channel_target.rs" - -[[bin]] -name = "msg_revoke_and_ack_target" -path = "fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs" - -[[bin]] -name = "msg_shutdown_target" -path = "fuzz_targets/msg_targets/msg_shutdown_target.rs" - -[[bin]] -name = "msg_update_fail_malformed_htlc_target" -path = "fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs" - -[[bin]] -name = "msg_update_fee_target" -path = "fuzz_targets/msg_targets/msg_update_fee_target.rs" - -[[bin]] -name = "msg_update_fulfill_htlc_target" -path = "fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs" - -[[bin]] -name = "msg_update_fail_htlc_target" -path = "fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs" - -[[bin]] -name = "msg_channel_reestablish_target" -path = "fuzz_targets/msg_targets/msg_channel_reestablish_target.rs" - -[[bin]] -name = "msg_announcement_signatures_target" -path = "fuzz_targets/msg_targets/msg_announcement_signatures_target.rs" - -[[bin]] -name = "msg_channel_announcement_target" -path = "fuzz_targets/msg_targets/msg_channel_announcement_target.rs" - -[[bin]] -name = "msg_channel_update_target" -path = "fuzz_targets/msg_targets/msg_channel_update_target.rs" - -[[bin]] -name = "msg_decoded_onion_error_packet_target" -path = "fuzz_targets/msg_targets/msg_decoded_onion_error_packet_target.rs" - -[[bin]] -name = "msg_init_target" -path = "fuzz_targets/msg_targets/msg_init_target.rs" - -[[bin]] -name = "msg_node_announcement_target" -path = "fuzz_targets/msg_targets/msg_node_announcement_target.rs" - -[[bin]] -name = "msg_onion_hop_data_target" -path = "fuzz_targets/msg_targets/msg_onion_hop_data_target.rs" +[lib] +name = "lightning_fuzz" +path = "src/lib.rs" +crate-type = ["rlib", "dylib", "staticlib"] diff --git a/fuzz/src/bin/chanmon_consistency_target.rs b/fuzz/src/bin/chanmon_consistency_target.rs new file mode 100644 index 000000000..a4a0bf23b --- /dev/null +++ b/fuzz/src/bin/chanmon_consistency_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::chanmon_consistency::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + chanmon_consistency_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + chanmon_consistency_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + chanmon_consistency_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + chanmon_consistency_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/chanmon_deser_target.rs b/fuzz/src/bin/chanmon_deser_target.rs new file mode 100644 index 000000000..91bc66c19 --- /dev/null +++ b/fuzz/src/bin/chanmon_deser_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::chanmon_deser::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + chanmon_deser_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + chanmon_deser_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + chanmon_deser_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + chanmon_deser_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/full_stack_target.rs b/fuzz/src/bin/full_stack_target.rs new file mode 100644 index 000000000..4dbf0cc91 --- /dev/null +++ b/fuzz/src/bin/full_stack_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::full_stack::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + full_stack_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + full_stack_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + full_stack_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + full_stack_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/gen_target.sh b/fuzz/src/bin/gen_target.sh new file mode 100755 index 000000000..9b5629e7c --- /dev/null +++ b/fuzz/src/bin/gen_target.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +echo "#include " > ../../targets.h +GEN_TEST() { + cat target_template.txt | sed s/TARGET_NAME/$1/ | sed s/TARGET_MOD/$2$1/ > $1_target.rs + echo "void $1_run(const unsigned char* data, size_t data_len);" >> ../../targets.h +} + +GEN_TEST chanmon_deser +GEN_TEST chanmon_consistency +GEN_TEST full_stack +GEN_TEST peer_crypt +GEN_TEST router + +GEN_TEST msg_accept_channel msg_targets:: +GEN_TEST msg_announcement_signatures msg_targets:: +GEN_TEST msg_channel_reestablish msg_targets:: +GEN_TEST msg_closing_signed msg_targets:: +GEN_TEST msg_commitment_signed msg_targets:: +GEN_TEST msg_decoded_onion_error_packet msg_targets:: +GEN_TEST msg_funding_created msg_targets:: +GEN_TEST msg_funding_locked msg_targets:: +GEN_TEST msg_funding_signed msg_targets:: +GEN_TEST msg_init msg_targets:: +GEN_TEST msg_open_channel msg_targets:: +GEN_TEST msg_revoke_and_ack msg_targets:: +GEN_TEST msg_shutdown msg_targets:: +GEN_TEST msg_update_fail_htlc msg_targets:: +GEN_TEST msg_update_fail_malformed_htlc msg_targets:: +GEN_TEST msg_update_fee msg_targets:: +GEN_TEST msg_update_fulfill_htlc msg_targets:: + +GEN_TEST msg_channel_announcement msg_targets:: +GEN_TEST msg_channel_update msg_targets:: +GEN_TEST msg_node_announcement msg_targets:: + +GEN_TEST msg_update_add_htlc msg_targets:: +GEN_TEST msg_error_message msg_targets:: +GEN_TEST msg_onion_hop_data msg_targets:: + +GEN_TEST msg_ping msg_targets:: +GEN_TEST msg_pong msg_targets:: diff --git a/fuzz/src/bin/msg_accept_channel_target.rs b/fuzz/src/bin/msg_accept_channel_target.rs new file mode 100644 index 000000000..c23560110 --- /dev/null +++ b/fuzz/src/bin/msg_accept_channel_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_accept_channel::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_accept_channel_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_accept_channel_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_accept_channel_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_accept_channel_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_announcement_signatures_target.rs b/fuzz/src/bin/msg_announcement_signatures_target.rs new file mode 100644 index 000000000..54f3d823d --- /dev/null +++ b/fuzz/src/bin/msg_announcement_signatures_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_announcement_signatures::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_announcement_signatures_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_announcement_signatures_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_announcement_signatures_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_announcement_signatures_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_channel_announcement_target.rs b/fuzz/src/bin/msg_channel_announcement_target.rs new file mode 100644 index 000000000..5ab797f67 --- /dev/null +++ b/fuzz/src/bin/msg_channel_announcement_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_channel_announcement::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_channel_announcement_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_channel_announcement_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_channel_announcement_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_channel_announcement_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_channel_reestablish_target.rs b/fuzz/src/bin/msg_channel_reestablish_target.rs new file mode 100644 index 000000000..79b23e409 --- /dev/null +++ b/fuzz/src/bin/msg_channel_reestablish_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_channel_reestablish::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_channel_reestablish_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_channel_reestablish_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_channel_reestablish_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_channel_reestablish_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_channel_update_target.rs b/fuzz/src/bin/msg_channel_update_target.rs new file mode 100644 index 000000000..f9dffda2d --- /dev/null +++ b/fuzz/src/bin/msg_channel_update_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_channel_update::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_channel_update_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_channel_update_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_channel_update_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_channel_update_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_closing_signed_target.rs b/fuzz/src/bin/msg_closing_signed_target.rs new file mode 100644 index 000000000..eee7145c7 --- /dev/null +++ b/fuzz/src/bin/msg_closing_signed_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_closing_signed::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_closing_signed_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_closing_signed_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_closing_signed_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_closing_signed_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_commitment_signed_target.rs b/fuzz/src/bin/msg_commitment_signed_target.rs new file mode 100644 index 000000000..6ce13f47b --- /dev/null +++ b/fuzz/src/bin/msg_commitment_signed_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_commitment_signed::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_commitment_signed_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_commitment_signed_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_commitment_signed_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_commitment_signed_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs b/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs new file mode 100644 index 000000000..c5c9d4a53 --- /dev/null +++ b/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_decoded_onion_error_packet::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_error_message_target.rs b/fuzz/src/bin/msg_error_message_target.rs new file mode 100644 index 000000000..1fa04d961 --- /dev/null +++ b/fuzz/src/bin/msg_error_message_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_error_message::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_error_message_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_error_message_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_error_message_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_error_message_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_funding_created_target.rs b/fuzz/src/bin/msg_funding_created_target.rs new file mode 100644 index 000000000..e9fedc3ce --- /dev/null +++ b/fuzz/src/bin/msg_funding_created_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_funding_created::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_funding_created_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_funding_created_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_funding_created_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_funding_created_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_funding_locked_target.rs b/fuzz/src/bin/msg_funding_locked_target.rs new file mode 100644 index 000000000..3665ce995 --- /dev/null +++ b/fuzz/src/bin/msg_funding_locked_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_funding_locked::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_funding_locked_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_funding_locked_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_funding_locked_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_funding_locked_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_funding_signed_target.rs b/fuzz/src/bin/msg_funding_signed_target.rs new file mode 100644 index 000000000..057cc6fe6 --- /dev/null +++ b/fuzz/src/bin/msg_funding_signed_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_funding_signed::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_funding_signed_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_funding_signed_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_funding_signed_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_funding_signed_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_init_target.rs b/fuzz/src/bin/msg_init_target.rs new file mode 100644 index 000000000..0bcbeda10 --- /dev/null +++ b/fuzz/src/bin/msg_init_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_init::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_init_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_init_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_init_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_init_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_node_announcement_target.rs b/fuzz/src/bin/msg_node_announcement_target.rs new file mode 100644 index 000000000..e3dde9fb6 --- /dev/null +++ b/fuzz/src/bin/msg_node_announcement_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_node_announcement::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_node_announcement_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_node_announcement_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_node_announcement_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_node_announcement_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_onion_hop_data_target.rs b/fuzz/src/bin/msg_onion_hop_data_target.rs new file mode 100644 index 000000000..ea2b6e4d4 --- /dev/null +++ b/fuzz/src/bin/msg_onion_hop_data_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_onion_hop_data::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_onion_hop_data_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_onion_hop_data_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_onion_hop_data_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_onion_hop_data_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_open_channel_target.rs b/fuzz/src/bin/msg_open_channel_target.rs new file mode 100644 index 000000000..690db561e --- /dev/null +++ b/fuzz/src/bin/msg_open_channel_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_open_channel::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_open_channel_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_open_channel_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_open_channel_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_open_channel_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_ping_target.rs b/fuzz/src/bin/msg_ping_target.rs new file mode 100644 index 000000000..871c8e147 --- /dev/null +++ b/fuzz/src/bin/msg_ping_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_ping::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_ping_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_ping_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_ping_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_ping_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_pong_target.rs b/fuzz/src/bin/msg_pong_target.rs new file mode 100644 index 000000000..c4fc46167 --- /dev/null +++ b/fuzz/src/bin/msg_pong_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_pong::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_pong_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_pong_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_pong_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_pong_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_revoke_and_ack_target.rs b/fuzz/src/bin/msg_revoke_and_ack_target.rs new file mode 100644 index 000000000..2c844c2aa --- /dev/null +++ b/fuzz/src/bin/msg_revoke_and_ack_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_revoke_and_ack::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_revoke_and_ack_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_revoke_and_ack_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_revoke_and_ack_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_revoke_and_ack_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_shutdown_target.rs b/fuzz/src/bin/msg_shutdown_target.rs new file mode 100644 index 000000000..ea1678ce2 --- /dev/null +++ b/fuzz/src/bin/msg_shutdown_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_shutdown::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_shutdown_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_shutdown_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_shutdown_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_shutdown_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_update_add_htlc_target.rs b/fuzz/src/bin/msg_update_add_htlc_target.rs new file mode 100644 index 000000000..cc8f67306 --- /dev/null +++ b/fuzz/src/bin/msg_update_add_htlc_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_update_add_htlc::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_update_add_htlc_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_update_add_htlc_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_update_add_htlc_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_update_add_htlc_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_update_fail_htlc_target.rs b/fuzz/src/bin/msg_update_fail_htlc_target.rs new file mode 100644 index 000000000..5099fed19 --- /dev/null +++ b/fuzz/src/bin/msg_update_fail_htlc_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_update_fail_htlc::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_update_fail_htlc_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_update_fail_htlc_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_update_fail_htlc_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_update_fail_htlc_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs b/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs new file mode 100644 index 000000000..9eea92797 --- /dev/null +++ b/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_update_fail_malformed_htlc::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_update_fee_target.rs b/fuzz/src/bin/msg_update_fee_target.rs new file mode 100644 index 000000000..50a96aa0b --- /dev/null +++ b/fuzz/src/bin/msg_update_fee_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_update_fee::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_update_fee_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_update_fee_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_update_fee_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_update_fee_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/msg_update_fulfill_htlc_target.rs b/fuzz/src/bin/msg_update_fulfill_htlc_target.rs new file mode 100644 index 000000000..35bf38e9a --- /dev/null +++ b/fuzz/src/bin/msg_update_fulfill_htlc_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::msg_targets::msg_update_fulfill_htlc::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/peer_crypt_target.rs b/fuzz/src/bin/peer_crypt_target.rs new file mode 100644 index 000000000..8c1f7b018 --- /dev/null +++ b/fuzz/src/bin/peer_crypt_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::peer_crypt::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + peer_crypt_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + peer_crypt_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + peer_crypt_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + peer_crypt_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/router_target.rs b/fuzz/src/bin/router_target.rs new file mode 100644 index 000000000..9b26a176b --- /dev/null +++ b/fuzz/src/bin/router_target.rs @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::router::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + router_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + router_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + router_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + router_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/src/bin/target_template.txt b/fuzz/src/bin/target_template.txt new file mode 100644 index 000000000..3ebb480df --- /dev/null +++ b/fuzz/src/bin/target_template.txt @@ -0,0 +1,44 @@ +// This file is auto-generated by gen_target.sh based on target_template.txt +// To modify it, modify target_template.txt and run gen_target.sh instead. + +//Uncomment this for libfuzzer builds: +//#![no_main] + +extern crate lightning_fuzz; +use lightning_fuzz::TARGET_MOD::*; + +use std::io::Read; + +#[cfg(feature = "afl")] +#[macro_use] extern crate afl; +#[cfg(feature = "afl")] +fn main() { + fuzz!(|data| { + TARGET_NAME_run(data.as_ptr(), data.len()); + }); +} + +#[cfg(feature = "honggfuzz")] +#[macro_use] extern crate honggfuzz; +#[cfg(feature = "honggfuzz")] +fn main() { + loop { + fuzz!(|data| { + TARGET_NAME_run(data.as_ptr(), data.len()); + }); + } +} + +#[cfg(feature = "libfuzzer_fuzz")] +#[macro_use] extern crate libfuzzer_sys; +#[cfg(feature = "libfuzzer_fuzz")] +fuzz_target!(|data: &[u8]| { + TARGET_NAME_run(data.as_ptr(), data.len()); +}); + +#[cfg(feature = "stdin_fuzz")] +fn main() { + let mut data = Vec::with_capacity(8192); + std::io::stdin().read_to_end(&mut data).unwrap(); + TARGET_NAME_run(data.as_ptr(), data.len()); +} diff --git a/fuzz/fuzz_targets/chanmon_fail_consistency.rs b/fuzz/src/chanmon_consistency.rs similarity index 97% rename from fuzz/fuzz_targets/chanmon_fail_consistency.rs rename to fuzz/src/chanmon_consistency.rs index b34d24215..4db35d957 100644 --- a/fuzz/fuzz_targets/chanmon_fail_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -9,14 +9,6 @@ //! send-side handling is correct, other peers. We consider it a failure if any action results in a //! channel being force-closed. -//Uncomment this for libfuzzer builds: -//#![no_main] - -extern crate bitcoin; -extern crate bitcoin_hashes; -extern crate lightning; -extern crate secp256k1; - use bitcoin::BitcoinHash; use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::{Transaction, TxOut}; @@ -44,7 +36,6 @@ use lightning::util::config::UserConfig; use lightning::util::events::{EventsProvider, MessageSendEventsProvider}; use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer}; -mod utils; use utils::test_logger; use secp256k1::key::{PublicKey,SecretKey}; @@ -745,34 +736,11 @@ pub fn do_test(data: &[u8]) { } } -#[cfg(feature = "afl")] -#[macro_use] extern crate afl; -#[cfg(feature = "afl")] -fn main() { - fuzz!(|data| { - do_test(data); - }); +#[no_mangle] +pub extern "C" fn chanmon_consistency_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -#[cfg(feature = "honggfuzz")] -#[macro_use] extern crate honggfuzz; -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|data| { - do_test(data); - }); - } -} - -#[cfg(feature = "libfuzzer_fuzz")] -#[macro_use] extern crate libfuzzer_sys; -#[cfg(feature = "libfuzzer_fuzz")] -fuzz_target!(|data: &[u8]| { - do_test(data); -}); - -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/chanmon_deser_target.rs b/fuzz/src/chanmon_deser.rs similarity index 77% rename from fuzz/fuzz_targets/chanmon_deser_target.rs rename to fuzz/src/chanmon_deser.rs index f74183258..5dde4a2ea 100644 --- a/fuzz/fuzz_targets/chanmon_deser_target.rs +++ b/fuzz/src/chanmon_deser.rs @@ -1,16 +1,11 @@ // 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 bitcoin; -extern crate bitcoin_hashes; -extern crate lightning; - use bitcoin_hashes::sha256d::Hash as Sha256dHash; use lightning::ln::channelmonitor; use lightning::util::ser::{ReadableArgs, Writer}; -mod utils; use utils::test_logger; use std::io::Cursor; @@ -41,30 +36,13 @@ pub fn do_test(data: &[u8]) { } } -#[cfg(feature = "afl")] -#[macro_use] extern crate afl; -#[cfg(feature = "afl")] -fn main() { - fuzz!(|data| { - do_test(data); - }); +#[no_mangle] +pub extern "C" fn chanmon_deser_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -#[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()); diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/src/full_stack.rs similarity index 98% rename from fuzz/fuzz_targets/full_stack_target.rs rename to fuzz/src/full_stack.rs index cf70569a3..4c3989d66 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/src/full_stack.rs @@ -4,14 +4,6 @@ //! or payments to send/ways to handle events generated. //! This test has been very useful, though due to its complexity good starting inputs are critical. -//Uncomment this for libfuzzer builds: -//#![no_main] - -extern crate bitcoin; -extern crate bitcoin_hashes; -extern crate lightning; -extern crate secp256k1; - use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::blockdata::script::{Builder, Script}; @@ -37,8 +29,6 @@ use lightning::util::events::{EventsProvider,Event}; use lightning::util::logger::Logger; use lightning::util::config::UserConfig; -mod utils; - use utils::test_logger; use secp256k1::key::{PublicKey,SecretKey}; @@ -532,37 +522,12 @@ pub fn do_test(data: &[u8], logger: &Arc) { } } -#[cfg(feature = "afl")] -#[macro_use] extern crate afl; -#[cfg(feature = "afl")] -fn main() { - fuzz!(|data| { - let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); - do_test(data, &logger); - }); +#[no_mangle] +pub extern "C" fn full_stack_run(data: *const u8, datalen: usize) { + let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, &logger); } -#[cfg(feature = "honggfuzz")] -#[macro_use] extern crate honggfuzz; -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|data| { - let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); - do_test(data, &logger); - }); - } -} - -#[cfg(feature = "libfuzzer_fuzz")] -#[macro_use] extern crate libfuzzer_sys; -#[cfg(feature = "libfuzzer_fuzz")] -fuzz_target!(|data: &[u8]| { - let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); - do_test(data, &logger); -}); - -extern crate hex; #[cfg(test)] mod tests { use utils::test_logger; diff --git a/fuzz/src/lib.rs b/fuzz/src/lib.rs new file mode 100644 index 000000000..fde5316cf --- /dev/null +++ b/fuzz/src/lib.rs @@ -0,0 +1,15 @@ +extern crate bitcoin; +extern crate bitcoin_hashes; +extern crate lightning; +extern crate secp256k1; +extern crate hex; + +mod utils; + +pub mod chanmon_deser; +pub mod chanmon_consistency; +pub mod full_stack; +pub mod peer_crypt; +pub mod router; + +pub mod msg_targets; diff --git a/fuzz/fuzz_targets/msg_targets/gen_target.sh b/fuzz/src/msg_targets/gen_target.sh similarity index 72% rename from fuzz/fuzz_targets/msg_targets/gen_target.sh rename to fuzz/src/msg_targets/gen_target.sh index cfd100f3d..fce89b26d 100755 --- a/fuzz/fuzz_targets/msg_targets/gen_target.sh +++ b/fuzz/src/msg_targets/gen_target.sh @@ -1,11 +1,16 @@ #!/bin/sh GEN_TEST() { - tn=$(echo $1 | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g') - fn=msg_$(echo $tn | tr '[:upper:]' '[:lower:]')_target.rs - cat msg_target_template.txt | sed s/MSG_TARGET/$1/ | sed "s/TEST_MSG/$2/" | sed "s/EXTRA_ARGS/$3/" > $fn + tn=msg_$(echo $1 | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]') + fn=${tn}.rs + cat msg_target_template.txt | sed s/MSG_TARGET/$1/ | sed "s/TARGET_NAME/$tn/" | sed "s/TEST_MSG/$2/" | sed "s/EXTRA_ARGS/$3/" > $fn + echo "pub mod $tn;" >> mod.rs } +echo "mod utils;" > mod.rs + +# Note when adding new targets here you should add a similar line in src/bin/gen_target.sh + GEN_TEST AcceptChannel test_msg "" GEN_TEST AnnouncementSignatures test_msg "" GEN_TEST ChannelReestablish test_msg "" diff --git a/fuzz/src/msg_targets/mod.rs b/fuzz/src/msg_targets/mod.rs new file mode 100644 index 000000000..5475381d4 --- /dev/null +++ b/fuzz/src/msg_targets/mod.rs @@ -0,0 +1,26 @@ +mod utils; +pub mod msg_accept_channel; +pub mod msg_announcement_signatures; +pub mod msg_channel_reestablish; +pub mod msg_closing_signed; +pub mod msg_commitment_signed; +pub mod msg_decoded_onion_error_packet; +pub mod msg_funding_created; +pub mod msg_funding_locked; +pub mod msg_funding_signed; +pub mod msg_init; +pub mod msg_open_channel; +pub mod msg_revoke_and_ack; +pub mod msg_shutdown; +pub mod msg_update_fail_htlc; +pub mod msg_update_fail_malformed_htlc; +pub mod msg_update_fee; +pub mod msg_update_fulfill_htlc; +pub mod msg_channel_announcement; +pub mod msg_channel_update; +pub mod msg_node_announcement; +pub mod msg_update_add_htlc; +pub mod msg_error_message; +pub mod msg_onion_hop_data; +pub mod msg_ping; +pub mod msg_pong; diff --git a/fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs b/fuzz/src/msg_targets/msg_accept_channel.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs rename to fuzz/src/msg_targets/msg_accept_channel.rs index 0f18d0232..04e3cc245 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs +++ b/fuzz/src/msg_targets/msg_accept_channel.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::AcceptChannel, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_accept_channel_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_announcement_signatures_target.rs b/fuzz/src/msg_targets/msg_announcement_signatures.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_announcement_signatures_target.rs rename to fuzz/src/msg_targets/msg_announcement_signatures.rs index 226028ea0..1df6aeca3 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_announcement_signatures_target.rs +++ b/fuzz/src/msg_targets/msg_announcement_signatures.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::AnnouncementSignatures, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_announcement_signatures_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_channel_announcement_target.rs b/fuzz/src/msg_targets/msg_channel_announcement.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_channel_announcement_target.rs rename to fuzz/src/msg_targets/msg_channel_announcement.rs index 0bdc10e85..9e2363eab 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_channel_announcement_target.rs +++ b/fuzz/src/msg_targets/msg_channel_announcement.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg_exact!(msgs::ChannelAnnouncement, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_channel_announcement_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs b/fuzz/src/msg_targets/msg_channel_reestablish.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs rename to fuzz/src/msg_targets/msg_channel_reestablish.rs index 4af593759..a81f0aebf 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs +++ b/fuzz/src/msg_targets/msg_channel_reestablish.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::ChannelReestablish, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_channel_reestablish_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_channel_update_target.rs b/fuzz/src/msg_targets/msg_channel_update.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_channel_update_target.rs rename to fuzz/src/msg_targets/msg_channel_update.rs index 724dca412..aaef33ea2 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_channel_update_target.rs +++ b/fuzz/src/msg_targets/msg_channel_update.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg_exact!(msgs::ChannelUpdate, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_channel_update_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs b/fuzz/src/msg_targets/msg_closing_signed.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs rename to fuzz/src/msg_targets/msg_closing_signed.rs index faeeae3eb..9a959d58c 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs +++ b/fuzz/src/msg_targets/msg_closing_signed.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::ClosingSigned, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_closing_signed_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs b/fuzz/src/msg_targets/msg_commitment_signed.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs rename to fuzz/src/msg_targets/msg_commitment_signed.rs index 97c4b3088..e84c98714 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs +++ b/fuzz/src/msg_targets/msg_commitment_signed.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::CommitmentSigned, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_commitment_signed_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_decoded_onion_error_packet_target.rs b/fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_decoded_onion_error_packet_target.rs rename to fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs index 9b190b086..e49d22b3a 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_decoded_onion_error_packet_target.rs +++ b/fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::DecodedOnionErrorPacket, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_decoded_onion_error_packet_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs b/fuzz/src/msg_targets/msg_error_message.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs rename to fuzz/src/msg_targets/msg_error_message.rs index d749dc91f..6b5bcccf2 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs +++ b/fuzz/src/msg_targets/msg_error_message.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg_hole!(msgs::ErrorMessage, data, 32, 2); } -#[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); - }); - } +#[no_mangle] +pub extern "C" fn msg_error_message_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs b/fuzz/src/msg_targets/msg_funding_created.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs rename to fuzz/src/msg_targets/msg_funding_created.rs index 45b257bb0..8e468a85a 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs +++ b/fuzz/src/msg_targets/msg_funding_created.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::FundingCreated, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_funding_created_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs b/fuzz/src/msg_targets/msg_funding_locked.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs rename to fuzz/src/msg_targets/msg_funding_locked.rs index cd1e89741..29e9c8a6a 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs +++ b/fuzz/src/msg_targets/msg_funding_locked.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::FundingLocked, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_funding_locked_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs b/fuzz/src/msg_targets/msg_funding_signed.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs rename to fuzz/src/msg_targets/msg_funding_signed.rs index 5992d6902..412558fe9 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs +++ b/fuzz/src/msg_targets/msg_funding_signed.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::FundingSigned, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_funding_signed_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_init_target.rs b/fuzz/src/msg_targets/msg_init.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_init_target.rs rename to fuzz/src/msg_targets/msg_init.rs index cdca84821..ece7beb69 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_init_target.rs +++ b/fuzz/src/msg_targets/msg_init.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::Init, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_init_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_node_announcement_target.rs b/fuzz/src/msg_targets/msg_node_announcement.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_node_announcement_target.rs rename to fuzz/src/msg_targets/msg_node_announcement.rs index f0a7a4c0d..95de73ba7 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_node_announcement_target.rs +++ b/fuzz/src/msg_targets/msg_node_announcement.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg_exact!(msgs::NodeAnnouncement, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_node_announcement_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_onion_hop_data_target.rs b/fuzz/src/msg_targets/msg_onion_hop_data.rs similarity index 52% rename from fuzz/fuzz_targets/msg_targets/msg_onion_hop_data_target.rs rename to fuzz/src/msg_targets/msg_onion_hop_data.rs index 058c050c5..0b02302ad 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_onion_hop_data_target.rs +++ b/fuzz/src/msg_targets/msg_onion_hop_data.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg_hole!(msgs::OnionHopData, data, 1+8+8+4, 12); } -#[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); - }); - } +#[no_mangle] +pub extern "C" fn msg_onion_hop_data_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs b/fuzz/src/msg_targets/msg_open_channel.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs rename to fuzz/src/msg_targets/msg_open_channel.rs index aa13e96dd..2688b4181 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs +++ b/fuzz/src/msg_targets/msg_open_channel.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::OpenChannel, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_open_channel_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_ping_target.rs b/fuzz/src/msg_targets/msg_ping.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_ping_target.rs rename to fuzz/src/msg_targets/msg_ping.rs index d2ea91335..21b74ad9f 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_ping_target.rs +++ b/fuzz/src/msg_targets/msg_ping.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_ping_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_pong_target.rs b/fuzz/src/msg_targets/msg_pong.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_pong_target.rs rename to fuzz/src/msg_targets/msg_pong.rs index 18120e2d1..c8fc4c59d 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_pong_target.rs +++ b/fuzz/src/msg_targets/msg_pong.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_pong_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs b/fuzz/src/msg_targets/msg_revoke_and_ack.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs rename to fuzz/src/msg_targets/msg_revoke_and_ack.rs index d82268d93..ca5412f5c 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs +++ b/fuzz/src/msg_targets/msg_revoke_and_ack.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::RevokeAndACK, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_revoke_and_ack_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs b/fuzz/src/msg_targets/msg_shutdown.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs rename to fuzz/src/msg_targets/msg_shutdown.rs index 34d4d2003..c249ffcec 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs +++ b/fuzz/src/msg_targets/msg_shutdown.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::Shutdown, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_shutdown_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_target_template.txt b/fuzz/src/msg_targets/msg_target_template.txt similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_target_template.txt rename to fuzz/src/msg_targets/msg_target_template.txt index 2704bcdff..6877918a5 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_target_template.txt +++ b/fuzz/src/msg_targets/msg_target_template.txt @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { TEST_MSG!(msgs::MSG_TARGET, dataEXTRA_ARGS); } -#[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); - }); - } +#[no_mangle] +pub extern "C" fn TARGET_NAME_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs b/fuzz/src/msg_targets/msg_update_add_htlc.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs rename to fuzz/src/msg_targets/msg_update_add_htlc.rs index e64a5c29f..960399abb 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs +++ b/fuzz/src/msg_targets/msg_update_add_htlc.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg_hole!(msgs::UpdateAddHTLC, data, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_update_add_htlc_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs b/fuzz/src/msg_targets/msg_update_fail_htlc.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs rename to fuzz/src/msg_targets/msg_update_fail_htlc.rs index fedce568e..8eb2870d3 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs +++ b/fuzz/src/msg_targets/msg_update_fail_htlc.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::UpdateFailHTLC, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_update_fail_htlc_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs b/fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs rename to fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs index 377378fcc..4d1ab282f 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs +++ b/fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::UpdateFailMalformedHTLC, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_update_fail_malformed_htlc_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs b/fuzz/src/msg_targets/msg_update_fee.rs similarity index 50% rename from fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs rename to fuzz/src/msg_targets/msg_update_fee.rs index 56b9ac424..8d3bb8941 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs +++ b/fuzz/src/msg_targets/msg_update_fee.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::UpdateFee, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_update_fee_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs b/fuzz/src/msg_targets/msg_update_fulfill_htlc.rs similarity index 51% rename from fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs rename to fuzz/src/msg_targets/msg_update_fulfill_htlc.rs index f0c936d1e..ab7277084 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs +++ b/fuzz/src/msg_targets/msg_update_fulfill_htlc.rs @@ -1,39 +1,20 @@ // 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; -mod utils; -use utils::VecWriter; +use msg_targets::utils::VecWriter; #[inline] pub fn do_test(data: &[u8]) { test_msg!(msgs::UpdateFulfillHTLC, 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); - }); - } +#[no_mangle] +pub extern "C" fn msg_update_fulfill_htlc_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { #[test] diff --git a/fuzz/fuzz_targets/msg_targets/utils.rs b/fuzz/src/msg_targets/utils.rs similarity index 100% rename from fuzz/fuzz_targets/msg_targets/utils.rs rename to fuzz/src/msg_targets/utils.rs diff --git a/fuzz/fuzz_targets/peer_crypt_target.rs b/fuzz/src/peer_crypt.rs similarity index 84% rename from fuzz/fuzz_targets/peer_crypt_target.rs rename to fuzz/src/peer_crypt.rs index 0b82303f8..8e6164464 100644 --- a/fuzz/fuzz_targets/peer_crypt_target.rs +++ b/fuzz/src/peer_crypt.rs @@ -1,6 +1,3 @@ -extern crate lightning; -extern crate secp256k1; - use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor; use secp256k1::key::{PublicKey,SecretKey}; @@ -78,30 +75,13 @@ pub fn do_test(data: &[u8]) { } } -#[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); - }); - } +#[no_mangle] +pub extern "C" fn peer_crypt_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { - #[test] fn duplicate_crash() { super::do_test(&::hex::decode("01").unwrap()); diff --git a/fuzz/fuzz_targets/router_target.rs b/fuzz/src/router.rs similarity index 94% rename from fuzz/fuzz_targets/router_target.rs rename to fuzz/src/router.rs index 9d06c19d6..3e8082e47 100644 --- a/fuzz/fuzz_targets/router_target.rs +++ b/fuzz/src/router.rs @@ -1,8 +1,3 @@ -extern crate bitcoin; -extern crate bitcoin_hashes; -extern crate lightning; -extern crate secp256k1; - use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin::blockdata::script::{Script, Builder}; use bitcoin::blockdata::block::Block; @@ -18,8 +13,6 @@ use lightning::util::ser::Readable; use secp256k1::key::PublicKey; -mod utils; - use utils::test_logger; use std::sync::Arc; @@ -238,30 +231,13 @@ pub fn do_test(data: &[u8]) { } } -#[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); - }); - } +#[no_mangle] +pub extern "C" fn router_run(data: *const u8, datalen: usize) { + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } -extern crate hex; #[cfg(test)] mod tests { - #[test] fn duplicate_crash() { super::do_test(&::hex::decode("00").unwrap()); diff --git a/fuzz/fuzz_targets/utils/mod.rs b/fuzz/src/utils/mod.rs similarity index 100% rename from fuzz/fuzz_targets/utils/mod.rs rename to fuzz/src/utils/mod.rs diff --git a/fuzz/fuzz_targets/utils/test_logger.rs b/fuzz/src/utils/test_logger.rs similarity index 100% rename from fuzz/fuzz_targets/utils/test_logger.rs rename to fuzz/src/utils/test_logger.rs diff --git a/fuzz/targets.h b/fuzz/targets.h new file mode 100644 index 000000000..430f614fb --- /dev/null +++ b/fuzz/targets.h @@ -0,0 +1,31 @@ +#include +void chanmon_deser_run(const unsigned char* data, size_t data_len); +void chanmon_consistency_run(const unsigned char* data, size_t data_len); +void full_stack_run(const unsigned char* data, size_t data_len); +void peer_crypt_run(const unsigned char* data, size_t data_len); +void router_run(const unsigned char* data, size_t data_len); +void msg_accept_channel_run(const unsigned char* data, size_t data_len); +void msg_announcement_signatures_run(const unsigned char* data, size_t data_len); +void msg_channel_reestablish_run(const unsigned char* data, size_t data_len); +void msg_closing_signed_run(const unsigned char* data, size_t data_len); +void msg_commitment_signed_run(const unsigned char* data, size_t data_len); +void msg_decoded_onion_error_packet_run(const unsigned char* data, size_t data_len); +void msg_funding_created_run(const unsigned char* data, size_t data_len); +void msg_funding_locked_run(const unsigned char* data, size_t data_len); +void msg_funding_signed_run(const unsigned char* data, size_t data_len); +void msg_init_run(const unsigned char* data, size_t data_len); +void msg_open_channel_run(const unsigned char* data, size_t data_len); +void msg_revoke_and_ack_run(const unsigned char* data, size_t data_len); +void msg_shutdown_run(const unsigned char* data, size_t data_len); +void msg_update_fail_htlc_run(const unsigned char* data, size_t data_len); +void msg_update_fail_malformed_htlc_run(const unsigned char* data, size_t data_len); +void msg_update_fee_run(const unsigned char* data, size_t data_len); +void msg_update_fulfill_htlc_run(const unsigned char* data, size_t data_len); +void msg_channel_announcement_run(const unsigned char* data, size_t data_len); +void msg_channel_update_run(const unsigned char* data, size_t data_len); +void msg_node_announcement_run(const unsigned char* data, size_t data_len); +void msg_update_add_htlc_run(const unsigned char* data, size_t data_len); +void msg_error_message_run(const unsigned char* data, size_t data_len); +void msg_onion_hop_data_run(const unsigned char* data, size_t data_len); +void msg_ping_run(const unsigned char* data, size_t data_len); +void msg_pong_run(const unsigned char* data, size_t data_len); diff --git a/fuzz/travis-fuzz.sh b/fuzz/travis-fuzz.sh index e602e9518..2c281d932 100755 --- a/fuzz/travis-fuzz.sh +++ b/fuzz/travis-fuzz.sh @@ -1,18 +1,23 @@ #!/bin/bash set -e -pushd fuzz_targets/msg_targets +pushd src/msg_targets +rm msg_*.rs +./gen_target.sh +[ "$(git diff)" != "" ] && exit 1 +popd +pushd src/bin rm *_target.rs ./gen_target.sh [ "$(git diff)" != "" ] && exit 1 popd cargo install --force honggfuzz -for TARGET in fuzz_targets/*.rs fuzz_targets/msg_targets/*_target.rs; do +for TARGET in src/bin/*.rs; do FILENAME=$(basename $TARGET) FILE="${FILENAME%.*}" HFUZZ_RUN_ARGS="--exit_upon_crash -v -n2" - if [ "$FILE" = "chanmon_fail_consistency" ]; then + if [ "$FILE" = "chanmon_consistency_target" ]; then HFUZZ_RUN_ARGS="$HFUZZ_RUN_ARGS -F 64 -N100000" else HFUZZ_RUN_ARGS="$HFUZZ_RUN_ARGS -N1000000" -- 2.39.5