Browse Source

psbt: return NULL instead of aborting on wally-lib problems

This lets us parse invalid/bad psbt data from user input without
crashing
paymod-01
niftynei 5 years ago
committed by Christian Decker
parent
commit
09815c7e7f
  1. 21
      bitcoin/tx.c

21
bitcoin/tx.c

@ -502,17 +502,22 @@ struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psb
* data, not the global tx. But 'finalizing' a tx destroys some fields
* so we 'clone' it first and then finalize it */
if (wally_psbt_clone(psbt, &tmppsbt) != WALLY_OK)
abort();
return NULL;
if (wally_finalize_psbt(tmppsbt) != WALLY_OK)
abort();
if (wally_finalize_psbt(tmppsbt) != WALLY_OK) {
wally_psbt_free(tmppsbt);
return NULL;
}
if (psbt_is_finalized(tmppsbt)) {
if (wally_extract_psbt(tmppsbt, &tx->wtx) != WALLY_OK)
abort();
} else if (wally_tx_clone(psbt->tx, &tx->wtx) != WALLY_OK)
abort();
if (wally_extract_psbt(tmppsbt, &tx->wtx) != WALLY_OK) {
wally_psbt_free(tmppsbt);
return NULL;
}
} else if (wally_tx_clone(psbt->tx, &tx->wtx) != WALLY_OK) {
wally_psbt_free(tmppsbt);
return NULL;
}
wally_psbt_free(tmppsbt);

Loading…
Cancel
Save