Skip to content

Commit 3e5fa8e

Browse files
devrandomksedgwic
authored andcommitted
Length prefix bitcoin tx, to fix layer violation
1 parent deace22 commit 3e5fa8e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bitcoin/tx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,14 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
705705
{
706706
struct bitcoin_tx *tx;
707707

708+
u32 len = fromwire_u32(cursor, max);
709+
size_t start = *max;
708710
tx = pull_bitcoin_tx(ctx, cursor, max);
709711
if (!tx)
710712
return fromwire_fail(cursor, max);
713+
// Check that we consumed len bytes
714+
if (start - *max != len)
715+
return fromwire_fail(cursor, max);
711716

712717
/* pull_bitcoin_tx sets the psbt */
713718
tal_free(tx->psbt);
@@ -749,6 +754,7 @@ void fromwire_bitcoin_outpoint(const u8 **cursor, size_t *max,
749754
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
750755
{
751756
u8 *lin = linearize_tx(tmpctx, tx);
757+
towire_u32(pptr, tal_count(lin));
752758
towire_u8_array(pptr, lin, tal_count(lin));
753759

754760
towire_wally_psbt(pptr, tx->psbt);

0 commit comments

Comments
 (0)