From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Wed, 16 Jan 2019 15:11:32 +0000 (-0500) Subject: Merge pull request #285 from TheBlueMatt/2019-01-fuzz-cleanups X-Git-Tag: v0.0.12~244 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;ds=sidebyside;h=7fd294db3db8a46ad4673d3f0200ad2a3ef178f0;hp=-c;p=rust-lightning Merge pull request #285 from TheBlueMatt/2019-01-fuzz-cleanups Trivial cleanups in full_stack_target/fuzztarget --- 7fd294db3db8a46ad4673d3f0200ad2a3ef178f0 diff --combined fuzz/fuzz_targets/full_stack_target.rs index 21acf2777,cd0c5cb7f..67146634e --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@@ -1,3 -1,12 +1,12 @@@ + //! Test that no series of bytes received over the wire/connections created/payments sent can + //! result in a crash. We do this by standing up a node and then reading bytes from input to denote + //! actions such as creating new inbound/outbound connections, bytes to be read from a connection, + //! 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; @@@ -9,11 -18,12 +18,12 @@@ use bitcoin::blockdata::script::{Builde use bitcoin::blockdata::opcodes; use bitcoin::consensus::encode::deserialize; use bitcoin::network::constants::Network; - use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160}; + use bitcoin::util::hash::{BitcoinHash, Sha256dHash}; use bitcoin_hashes::Hash as TraitImport; use bitcoin_hashes::HashEngine as TraitImportEngine; use bitcoin_hashes::sha256::Hash as Sha256; + use bitcoin_hashes::hash160::Hash as Hash160; use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil}; use lightning::chain::transaction::OutPoint; @@@ -235,7 -245,7 +245,7 @@@ impl KeysInterface for KeyProvider fn get_destination_script(&self) -> Script { let secp_ctx = Secp256k1::signing_only(); let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(); - let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize()); + let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize()); Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script() } @@@ -540,6 -550,14 +550,14 @@@ fn main() } } + #[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{}); + do_test(data, &logger); + }); + extern crate hex; #[cfg(test)] mod tests { @@@ -853,6 -871,6 +871,6 @@@ assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030200000000000000000000000000000000000000000000000000000000000000 with 1 adds, 0 fulfills, 0 fails for channel 3f00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&3)); // 7 assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 1 fulfills, 0 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&1)); // 8 assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000000 with 0 adds, 0 fulfills, 1 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000".to_string())), Some(&2)); // 9 - assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending 00000000000000000000000000000000000000000000000000000000000000fb:0 resolves HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 from remote commitment tx".to_string())), Some(&1)); // 10 + assert_eq!(log_entries.get(&("lightning::ln::channelmonitor".to_string(), "Input spending remote commitment tx (00000000000000000000000000000000000000000000000000000000000000fb:0) in 0000000000000000000000000000000000000000000000000000000000000042 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout".to_string())), Some(&1)); // 10 } }