From e393791d4bd405cd7c764b3a612a22d88014dfc5 Mon Sep 17 00:00:00 2001 From: Devrandom Date: Fri, 24 Sep 2021 14:34:39 +0200 Subject: [PATCH] Length prefix bitcoin tx, to fix layer violation --- bitcoin/tx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 4aa490f0e..d676b06da 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -700,9 +700,14 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx, { struct bitcoin_tx *tx; + u32 len = fromwire_u32(cursor, max); + size_t start = *max; tx = pull_bitcoin_tx(ctx, cursor, max); if (!tx) return fromwire_fail(cursor, max); + // Check that we consumed len bytes + if (start - *max != len) + return fromwire_fail(cursor, max); /* pull_bitcoin_tx sets the psbt */ tal_free(tx->psbt); @@ -744,6 +749,7 @@ void fromwire_bitcoin_outpoint(const u8 **cursor, size_t *max, void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx) { u8 *lin = linearize_tx(tmpctx, tx); + towire_u32(pptr, tal_count(lin)); towire_u8_array(pptr, lin, tal_count(lin)); towire_wally_psbt(pptr, tx->psbt);