bitcoin: don't dereference a NULL transaction from a truncated block - #9485
Open
kwsantiago wants to merge 1 commit into
Open
bitcoin: don't dereference a NULL transaction from a truncated block#9485kwsantiago wants to merge 1 commit into
kwsantiago wants to merge 1 commit into
Conversation
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.
kwsantiago
force-pushed
the
fix/null-tx-truncated-block
branch
from
September 8, 2026 19:22
f216449 to
439071e
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 that ends part-way through a transaction segfaults lightningd rather than being rejected by the
if (!p || len)check a few lines below, which never runs.Reproducer, on master with no other changes: truncating the block already in
run-bitcoin_block_from_hexto 162 bytes is enough.The block arrives from the chain backend through
getrawblockbyheight, so triggering it needs a bitcoind serving a malformed or otherwise unparseable block, not anything a peer can send. It is a crash on bad input from a trusted component rather than a remotely reachable issue, which is why this is a normal pull request.The fix returns NULL the way every other parse failure in this function does. The test walks every truncation of the existing test block, so it covers the header boundary and each transaction boundary rather than one hand-picked length.