From 14aeece462b149eaf0d28a37d55cc169df99b2cb Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sat, 16 Jul 2022 13:22:46 +0200 Subject: CBlockIndex: ensure phashBlock is not nullptr before dereferencing and remove a now-redundant assert preceding a GetBlockHash() caller. This protects against UB here, and in case of failure (which would indicate a consensus bug), the debug log will print bitcoind: chain.h:265: uint256 CBlockIndex::GetBlockHash() const: Assertion `phashBlock != nullptr' failed. Aborted instead of Segmentation fault --- src/chain.h | 1 + src/validation.cpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index ecc2ae732f..1a499b07cc 100644 --- a/src/chain.h +++ b/src/chain.h @@ -263,6 +263,7 @@ public: uint256 GetBlockHash() const { + assert(phashBlock != nullptr); return *phashBlock; } diff --git a/src/validation.cpp b/src/validation.cpp index 4c694a2c21..d53661f1f2 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2263,7 +2263,6 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, m_blockman.m_dirty_blockindex.insert(pindex); } - assert(pindex->phashBlock); // add this block to the view's block chain view.SetBestBlock(pindex->GetBlockHash()); -- cgit v1.2.3