From 08d32123d8bdb083a14f67358edcfdb11f6b3cb8 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Mon, 10 May 2021 01:37:51 +0200 Subject: [PATCH] bitcoin/tx: check PSBT sanity after parsing We could end up handing a valid tx containing a NULL PSBT around. Signed-off-by: Antoine Poinsot --- bitcoin/tx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index c7ffe12ee..01e723caa 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -595,6 +595,8 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor, tal_add_destructor(tx, bitcoin_tx_destroy); tx->chainparams = chainparams; tx->psbt = new_psbt(tx, tx->wtx); + if (!tx->psbt) + return tal_free(tx); return tx; } @@ -710,6 +712,8 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx, /* pull_bitcoin_tx sets the psbt */ tal_free(tx->psbt); tx->psbt = fromwire_wally_psbt(tx, cursor, max); + if (!tx->psbt) + return fromwire_fail(cursor, max); return tx; }