From 09815c7e7fc4406f5c2461a98afb5077d642f277 Mon Sep 17 00:00:00 2001 From: niftynei Date: Fri, 29 May 2020 12:13:47 -0500 Subject: [PATCH] psbt: return NULL instead of aborting on wally-lib problems This lets us parse invalid/bad psbt data from user input without crashing --- bitcoin/tx.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 10f3f3a28..a9f67f6fe 100644 --- a/bitcoin/tx.c +++ b/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);