diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-03-20 12:46:08 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-03-20 12:46:11 +0100 |
commit | 63952f73b3041468fe3b25fa54858db7899273fa (patch) | |
tree | 7a7fe66244b118c84c1e04b59728eaa9ed3b56b8 /src | |
parent | 3530d5d2d851d025b013b2ea79ed39a57cbbafcd (diff) | |
parent | 787df19b09babf50dd8124b3ac990b29c33cfe93 (diff) |
Merge #20921: validation: don't try to invalidate genesis block in CChainState::InvalidateBlock
787df19b09babf50dd8124b3ac990b29c33cfe93 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 787df19b09babf50dd8124b3ac990b29c33cfe93. Tested invalidation of generic on regtest.
practicalswift:
Tested ACK 787df19b09babf50dd8124b3ac990b29c33cfe93
Tree-SHA512: 978be7cf2bd1c1faebfe945d191ac77dea72791bea826459abd308f77c74c5991efee495a38817c306e488ecd5208b5c888df7d9d044132dd9a06bbbdb256b6c
Diffstat (limited to 'src')
-rw-r--r-- | src/validation.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 74df13f462..96d12f10e2 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2974,6 +2974,10 @@ bool CChainState::PreciousBlock(BlockValidationState& state, const CChainParams& bool CChainState::InvalidateBlock(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex) { + // Genesis block can't be invalidated + assert(pindex); + if (pindex->nHeight == 0) return false; + CBlockIndex* to_mark_failed = pindex; bool pindex_was_in_chain = false; int disconnected = 0; |