Skip to content

Commit

Permalink
peer_control: Fix check_funding_details assert
Browse files Browse the repository at this point in the history
Check funding_outnum validity first to avoid reading invalid outputs

Changelog-Fixed: Fixed a potential issue if the number of outputs decreases in a dualopen RBF or splice.
  • Loading branch information
ddustin committed Jul 5, 2022
1 parent 669bca4 commit 275b534
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,13 +1437,14 @@ static bool check_funding_details(const struct bitcoin_tx *tx,
struct amount_sat funding,
u32 funding_outnum)
{
struct amount_asset asset =
bitcoin_tx_output_get_amount(tx, funding_outnum);
struct amount_asset asset;

if (!amount_asset_is_main(&asset))
if (funding_outnum >= tx->wtx->num_outputs)
return false;

if (funding_outnum >= tx->wtx->num_outputs)
asset = bitcoin_tx_output_get_amount(tx, funding_outnum);

if (!amount_asset_is_main(&asset))
return false;

if (!amount_sat_eq(amount_asset_to_sat(&asset), funding))
Expand Down

0 comments on commit 275b534

Please sign in to comment.