From f314bc8091d05c0cf80d799ed09e4938b27c01c7 Mon Sep 17 00:00:00 2001 From: VictorLux Date: Tue, 9 Jun 2026 22:29:10 +0200 Subject: [PATCH] Fix NULL-pointer dereference on the genesis block during -reindex / import AcceptBlockHeader dereferenced pindexPrev for the genesis block (which has no predecessor) -> segfault that aborts every -reindex / block import at startup. Guard the genesis case. Reliability fix; no consensus change. Co-Authored-By: Claude Opus 4.8 --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index eb98a68c72d..31f94009b17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4473,7 +4473,11 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc return false; - if (!pindexPrev->IsValid(BLOCK_VALID_SCRIPTS)) { + // pindexPrev is NULL for the genesis block (set only for non-genesis above). + // The genesis block has no ancestors, so the invalid-ancestor walk below is + // meaningless for it; guard the dereference to avoid a NULL segfault during + // -reindex / import, where LoadExternalBlockFile re-accepts the genesis header. + if (pindexPrev != NULL && !pindexPrev->IsValid(BLOCK_VALID_SCRIPTS)) { for (const CBlockIndex *failedit : g_failed_blocks) { if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) { assert(failedit->nStatus & BLOCK_FAILED_MASK);