]> Untitled Git - bdk/commitdiff
fix(wallet): improve safety on finaize psbt
authorf3r10 <frledesma@outlook.com>
Sun, 5 Jan 2025 17:55:49 +0000 (12:55 -0500)
committerf3r10 <frledesma@outlook.com>
Sun, 5 Jan 2025 17:55:49 +0000 (12:55 -0500)
crates/wallet/src/wallet/mod.rs

index 68d5e6bec28cc44ec6cb0f35d68d2c68e8877552..55922594726aff81bc0d4d851152115efe792ff7 100644 (file)
@@ -1879,8 +1879,11 @@ impl Wallet {
                         Ok(_) => {
                             // Set the UTXO fields, final script_sig and witness
                             // and clear everything else.
-                            let original = mem::take(&mut psbt.inputs[n]);
-                            let psbt_input = &mut psbt.inputs[n];
+                            let psbt_input = psbt
+                                .inputs
+                                .get_mut(n)
+                                .ok_or(SignerError::InputIndexOutOfRange)?;
+                            let original = mem::take(psbt_input);
                             psbt_input.non_witness_utxo = original.non_witness_utxo;
                             psbt_input.witness_utxo = original.witness_utxo;
                             if !tmp_input.script_sig.is_empty() {