]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Check too many tx outputs upfront when verifying funding tx
authorbenthecarman <benthecarman@live.com>
Mon, 8 May 2023 22:49:05 +0000 (17:49 -0500)
committerbenthecarman <benthecarman@live.com>
Mon, 8 May 2023 22:49:05 +0000 (17:49 -0500)
lightning/src/ln/channelmanager.rs

index 3bf215d0a4aef8d40a923b332ea62c44f403a199..0742d96d1215347df627cbc542ae185bee8aa2f7 100644 (file)
@@ -3090,6 +3090,12 @@ where
                        }
                }
                self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, |chan, tx| {
+                       if tx.output.len() > u16::max_value() as usize {
+                               return Err(APIError::APIMisuseError {
+                                       err: "Transaction had more than 2^16 outputs, which is not supported".to_owned()
+                               });
+                       }
+
                        let mut output_index = None;
                        let expected_spk = chan.get_funding_redeemscript().to_v0_p2wsh();
                        for (idx, outp) in tx.output.iter().enumerate() {
@@ -3099,11 +3105,6 @@ where
                                                        err: "Multiple outputs matched the expected script and value".to_owned()
                                                });
                                        }
-                                       if idx > u16::max_value() as usize {
-                                               return Err(APIError::APIMisuseError {
-                                                       err: "Transaction had more than 2^16 outputs, which is not supported".to_owned()
-                                               });
-                                       }
                                        output_index = Some(idx as u16);
                                }
                        }