bitcoin: don't dereference a NULL transaction from a truncated block - #9485
Open
kwsantiago wants to merge 2 commits into
Open
kwsantiago wants to merge 2 commits into
kwsantiago wants to merge 2 commits into
Conversation
kwsantiago
force-pushed
the
fix/null-tx-truncated-block
branch
from
September 8, 2026 19:22
f216449 to
439071e
Compare
pull_bitcoin_tx_only() returns NULL once the cursor runs out, and the next line writes through it, so a block that ends mid-transaction segfaults lightningd instead of being rejected. The block comes from the chain backend via getrawblockbyheight, so this needs a bitcoind serving a malformed or unparseable block rather than anything a peer can send. Test walks every truncation of the existing test block; it segfaults at 162 bytes without the fix.
daywalker90
force-pushed
the
fix/null-tx-truncated-block
branch
from
September 16, 2026 16:10
439071e to
1f722b5
Compare
Collaborator
|
CI caught a leak: |
linear_tx hangs off ctx, so the failure paths free b and leave it behind.
kwsantiago
force-pushed
the
fix/null-tx-truncated-block
branch
from
September 16, 2026 17:18
37c4c2c to
6d82425
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pull_bitcoin_tx_only()returns NULL once the cursor runs out, and the next line writes through it, so a block ending part-way through a transaction segfaults lightningd instead of being rejected by theif (!p || len)check below.Truncating the block already in
run-bitcoin_block_from_hexto 162 bytes is enough:The block arrives from the chain backend through
getrawblockbyheight, so this needs a bitcoind serving a malformed block, not anything a peer can send.The test walks every truncation of the existing test block, covering the header and each transaction boundary rather than one hand-picked length.
Second commit fixes a leak that test exposed:
linear_txhangs offctx, so the failure paths freeband leave it behind. Under the Makefile's valgrind invocation, 2,143,160 bytes in 2,849 blocks before, none after.Changelog-None