Skip to content

Commit 14aeece

Browse files
committed
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
1 parent 02ede4f commit 14aeece

File tree

2 files changed

+1
-1
lines changed

2 files changed

+1
-1
lines changed

src/chain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class CBlockIndex
263263

264264
uint256 GetBlockHash() const
265265
{
266+
assert(phashBlock != nullptr);
266267
return *phashBlock;
267268
}
268269

src/validation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,6 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
22632263
m_blockman.m_dirty_blockindex.insert(pindex);
22642264
}
22652265

2266-
assert(pindex->phashBlock);
22672266
// add this block to the view's block chain
22682267
view.SetBestBlock(pindex->GetBlockHash());
22692268

0 commit comments

Comments
 (0)