Merge pull request #265 from TheBlueMatt/2018-12-fuzz-fix-no-witness

Fix crash on no-witness tx in ChannelMonitor found by fuzzer
This commit is contained in:
Matt Corallo 2018-12-03 14:38:56 -05:00 committed by GitHub
commit dfbc6c60a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View file

@ -7,7 +7,7 @@ use bitcoin::blockdata::block::BlockHeader;
use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::blockdata::transaction::{Transaction, TxOut};
use bitcoin::blockdata::script::{Builder, Script}; use bitcoin::blockdata::script::{Builder, Script};
use bitcoin::blockdata::opcodes; use bitcoin::blockdata::opcodes;
use bitcoin::consensus::encode::{deserialize, serialize}; use bitcoin::consensus::encode::deserialize;
use bitcoin::network::constants::Network; use bitcoin::network::constants::Network;
use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160}; use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160};

View file

@ -4,7 +4,9 @@ pub struct TestLogger {}
impl Logger for TestLogger { impl Logger for TestLogger {
fn log(&self, record: &Record) { 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); println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
#[cfg(not(test))]
let _ = format!("{}", record.args);
} }
} }

View file

@ -1386,7 +1386,7 @@ impl ChannelMonitor {
/// Generate a spendable output event when closing_transaction get registered onchain. /// Generate a spendable output event when closing_transaction get registered onchain.
fn check_spend_closing_transaction(&self, tx: &Transaction) -> Option<SpendableOutputDescriptor> { fn check_spend_closing_transaction(&self, tx: &Transaction) -> Option<SpendableOutputDescriptor> {
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 { match self.key_storage {
KeyStorage::PrivMode { ref shutdown_pubkey, .. } => { KeyStorage::PrivMode { ref shutdown_pubkey, .. } => {
let our_channel_close_key_hash = Hash160::from_data(&shutdown_pubkey.serialize()); let our_channel_close_key_hash = Hash160::from_data(&shutdown_pubkey.serialize());