From f9c945e17fd39c7a7250b18f0053798e0b92c19d Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 2 Dec 2018 18:22:40 -0500 Subject: [PATCH 1/3] Fix crash on no-witness tx in ChannelMonitor found by fuzzer Tehnically we can't currently hit this, but a theoretical future watchtower could, and full_stack_target crashes on it. --- src/ln/channelmonitor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 6ce4b22d5..cee406d00 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -1386,7 +1386,7 @@ impl ChannelMonitor { /// Generate a spendable output event when closing_transaction get registered onchain. fn check_spend_closing_transaction(&self, tx: &Transaction) -> Option { - if tx.input[0].sequence == 0xFFFFFFFF && tx.input[0].witness.last().unwrap().len() == 71 { + if tx.input[0].sequence == 0xFFFFFFFF && !tx.input[0].witness.is_empty() && tx.input[0].witness.last().unwrap().len() == 71 { match self.key_storage { KeyStorage::PrivMode { ref shutdown_pubkey, .. } => { let our_channel_close_key_hash = Hash160::from_data(&shutdown_pubkey.serialize()); From 7e94d3a6179a829a598b2acb9958a5a3bed081a6 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 3 Dec 2018 13:30:18 -0500 Subject: [PATCH 2/3] Remove unused import in full_stack_target --- fuzz/fuzz_targets/full_stack_target.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index 354625604..0524f578e 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -7,7 +7,7 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::blockdata::script::{Builder, Script}; use bitcoin::blockdata::opcodes; -use bitcoin::consensus::encode::{deserialize, serialize}; +use bitcoin::consensus::encode::deserialize; use bitcoin::network::constants::Network; use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160}; From 4f9b0fbd3f3b252ceb8e9aeb19c2d0635294dc1e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 3 Dec 2018 13:58:11 -0500 Subject: [PATCH 3/3] Avoid writing to stdout during fuzz tests --- fuzz/fuzz_targets/utils/test_logger.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fuzz/fuzz_targets/utils/test_logger.rs b/fuzz/fuzz_targets/utils/test_logger.rs index 2ef1196b5..f828d0638 100644 --- a/fuzz/fuzz_targets/utils/test_logger.rs +++ b/fuzz/fuzz_targets/utils/test_logger.rs @@ -4,7 +4,9 @@ pub struct TestLogger {} impl Logger for TestLogger { fn log(&self, record: &Record) { - #[cfg(any(test, not(feature = "fuzztarget")))] + #[cfg(test)] println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args); + #[cfg(not(test))] + let _ = format!("{}", record.args); } }