Skip to content

Commit 63952f7

Browse files
author
MarcoFalke
committed
Merge #20921: validation: don't try to invalidate genesis block in CChainState::InvalidateBlock
787df19 validation: don't try to invalidate genesis block (Sebastian Falbesoner) Pull request description: In the block invalidation method (`CChainState::InvalidateBlock`), the code for creating the candidate block map assumes that the passed block's previous block (`pindex->pprev`) is available and otherwise segfaults due to null-pointer deference in `CBlockIndexWorkComparator()` (see analysis by practicalswift in #20914), i.e. it doesn't work with the genesis block. Rather than analyzing all possible code paths and implications for this corner case, simply fail early if the genesis block is passed. Fixes #20914. ACKs for top commit: sipa: ACK 787df19. Tested invalidation of generic on regtest. practicalswift: Tested ACK 787df19 Tree-SHA512: 978be7cf2bd1c1faebfe945d191ac77dea72791bea826459abd308f77c74c5991efee495a38817c306e488ecd5208b5c888df7d9d044132dd9a06bbbdb256b6c
2 parents 3530d5d + 787df19 commit 63952f7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/validation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,10 @@ bool CChainState::PreciousBlock(BlockValidationState& state, const CChainParams&
29742974

29752975
bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex)
29762976
{
2977+
// Genesis block can't be invalidated
2978+
assert(pindex);
2979+
if (pindex->nHeight == 0) return false;
2980+
29772981
CBlockIndex* to_mark_failed = pindex;
29782982
bool pindex_was_in_chain = false;
29792983
int disconnected = 0;

0 commit comments

Comments
 (0)