From e8a96389bac78961220cbc095c820a551ce4dacf Mon Sep 17 00:00:00 2001 From: f3r10 Date: Sun, 5 Jan 2025 12:55:49 -0500 Subject: [PATCH] fix(wallet): improve safety on finaize psbt --- crates/wallet/src/wallet/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index 68d5e6be..55922594 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -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() { -- 2.49.0