From 14a2e1ba9644d0cc59c1f773d330a8f2674ab54b Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 26 Jul 2021 22:40:39 +0100 Subject: consensus: Fix a rare crash bug Fix a rare crash bug where no best chain can be activated, and therefore when trying to find the height of the best chain via the last block triggers a null pointer dereference. --- src/validation.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/validation.cpp') diff --git a/src/validation.cpp b/src/validation.cpp index 35778a2e7..c81ab3c20 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2573,7 +2573,11 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, } } while (pindexNewTip != pindexMostWork); - CheckBlockIndex(chainparams.GetConsensus(pindexNewTip->nHeight)); + if (pindexNewTip != NULL) { + CheckBlockIndex(chainparams.GetConsensus(pindexNewTip->nHeight)); + } else { + CheckBlockIndex(chainparams.GetConsensus(0)); + } // Write changes periodically to disk, after relay. if (!FlushStateToDisk(state, FLUSH_STATE_PERIODIC)) { -- cgit v1.2.3