Skip to content

Commit 63c2d83

Browse files
Explicitly state assumption that state.m_chain_sync.m_work_header != nullptr in ConsiderEviction
Static analyzer (and humans!) will see ... ``` else if (state.m_chain_sync.m_timeout == 0 || (state.m_chain_sync.m_work_header != nullptr && ... ``` ... and infer that state.m_chain_sync.m_work_header might be set to nullptr, and thus flag `state.m_chain_sync.m_work_header->GetBlockHash().ToString()` as a potential null pointer dereference. This commit makes the tacit assumption (m_work_header != nullptr) explicit. Code introduced in 5a6d00 ("Permit disconnection of outbound peers on bad/slow chains") which was merged into master four days ago.
1 parent fe503e1 commit 63c2d83

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,7 @@ void PeerLogicValidation::ConsiderEviction(CNode *pto, int64_t time_in_seconds)
30063006
LogPrintf("Disconnecting outbound peer %d for old chain, best known block = %s\n", pto->GetId(), state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>");
30073007
pto->fDisconnect = true;
30083008
} else {
3009+
assert(state.m_chain_sync.m_work_header);
30093010
LogPrint(BCLog::NET, "sending getheaders to outbound peer=%d to verify chain work (current best known block:%s, benchmark blockhash: %s)\n", pto->GetId(), state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>", state.m_chain_sync.m_work_header->GetBlockHash().ToString());
30103011
connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(state.m_chain_sync.m_work_header->pprev), uint256()));
30113012
state.m_chain_sync.m_sent_getheaders = true;

0 commit comments

Comments
 (0)