lightningd: fix crash on fixup scan if block unavailable.
What changed, and why it matters
This commit fixes a bug where Core Lightning could crash with a segmentation fault (FATAL SIGNAL 11) during startup if the connected Bitcoin node could not provide a requested block. The crash occurred because a function tried to use a block that was not actually loaded. The fix adds a simple check: if the block is missing, log a warning and try again on the next restart instead of crashing.
Apply the patch. It is a small, safe defensive fix. Operators should also ensure their bitcoind is fully synced before starting lightningd to avoid the retry-on-restart loop.
Security signals we found
NULL pointer dereference (SIGSEGV) in startup code path
Crash triggered by missing block data from external Bitcoin backend
Fix adds defensive NULL check in asynchronous callback
Changelog labels this as a fixed potential crash on startup
Evidence from the diff
In lightningd/chaintopology.c, fixup_scan_block() is called as a callback after requesting a block by height. Previously it dereferenced blk without checking for NULL. If the block was unavailable (e.g., bitcoind not fully synced or transient RPC failure), blk was NULL and the function crashed at line 1531. The patch adds a NULL guard at the top of the callback, logs an unusual event, and returns early. The caller will retry on next restart.
Changed components
lightningd/chaintopology.cfixup_scan_block()getrawblockbyheight_callback() in lightningd/bitcoind.cInspect captured patch +8 / −0
diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c
index f977dc45..9cb12379 100644
--- a/lightningd/chaintopology.c
+++ b/lightningd/chaintopology.c
@@ -1528,6 +1528,14 @@ static void fixup_scan_block(struct bitcoind *bitcoind,
struct bitcoin_block *blk,
struct chain_topology *topo)
{
+ /* Can't scan the block? We will try again next restart */
+ if (!blk) {
+ log_unusual(topo->ld->log,
+ "fixup_scan: could not load block %u, will retry next restart",
+ height);
+ return;
+ }
+
log_debug(topo->ld->log, "fixup_scan: block %u with %zu txs", height, tal_count(blk->tx));
topo_update_spends(topo, blk->tx, blk->txids, height);
Why this scored 54/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.