HomePhabricator

CBlockIndex: ensure phashBlock is not nullptr before dereferencing

Description

CBlockIndex: ensure phashBlock is not nullptr before dereferencing

Summary:
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: blockindex.h:148: BlockHash CBlockIndex::GetBlockHash() const: Assertion `phashBlock != nullptr' failed.
Aborted

instead of

Segmentation fault

This is a partial backport of core#25349
https://github.com/bitcoin/bitcoin/pull/25349/commits/14aeece462b149eaf0d28a37d55cc169df99b2cb
Depends on D16069

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16070

Details

Provenance
Jon Atack <jon@atack.com>Authored on Jul 16 2022, 11:22
PiRKCommitted on Apr 29 2024, 18:16
PiRKPushed on Apr 29 2024, 18:16
Reviewer
Restricted Project
Differential Revision
D16070: CBlockIndex: ensure phashBlock is not nullptr before dereferencing
Parents
rABCbb8db084544e: Remove unused SetTip(nullptr) code
Branches
Unknown
Tags
Unknown