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

This lets us parse invalid/bad psbt data from user input without
crashing
This commit is contained in:
niftynei
2020-05-29 12:13:47 -05:00
committed by Christian Decker
parent 5ecacf3dd0
commit 09815c7e7f

View File

@@ -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);