Skip to content

Commit fcd1127

Browse files
committed
Check too many tx outputs upfront when verifying funding tx
1 parent 818dbdf commit fcd1127

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,12 @@ where
30903090
}
30913091
}
30923092
self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, |chan, tx| {
3093+
if tx.output.len() > u16::max_value() as usize {
3094+
return Err(APIError::APIMisuseError {
3095+
err: "Transaction had more than 2^16 outputs, which is not supported".to_owned()
3096+
});
3097+
}
3098+
30933099
let mut output_index = None;
30943100
let expected_spk = chan.get_funding_redeemscript().to_v0_p2wsh();
30953101
for (idx, outp) in tx.output.iter().enumerate() {
@@ -3099,11 +3105,6 @@ where
30993105
err: "Multiple outputs matched the expected script and value".to_owned()
31003106
});
31013107
}
3102-
if idx > u16::max_value() as usize {
3103-
return Err(APIError::APIMisuseError {
3104-
err: "Transaction had more than 2^16 outputs, which is not supported".to_owned()
3105-
});
3106-
}
31073108
output_index = Some(idx as u16);
31083109
}
31093110
}

0 commit comments

Comments
 (0)