mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-10 14:48:46 +02:00
Change CChain::Next() to take reference
To minimize chance of erroneous nullptr dereference, `CChain::Next()` is changed to take a reference instead of a pointer. Call sites have been adapted. Notably, NextSyncBlock() now checks the FindFork() result before calling into Next(), because the fork lookup may return null.
This commit is contained in:
@@ -4215,10 +4215,10 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
// Send the rest of the chain
|
||||
if (pindex)
|
||||
pindex = m_chainman.ActiveChain().Next(pindex);
|
||||
pindex = m_chainman.ActiveChain().Next(*pindex);
|
||||
int nLimit = 500;
|
||||
LogDebug(BCLog::NET, "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom.GetId());
|
||||
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex))
|
||||
for (; pindex; pindex = m_chainman.ActiveChain().Next(*pindex))
|
||||
{
|
||||
if (pindex->GetBlockHash() == hashStop)
|
||||
{
|
||||
@@ -4354,14 +4354,14 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
// Find the last block the caller has in the main chain
|
||||
pindex = m_chainman.ActiveChainstate().FindForkInGlobalIndex(locator);
|
||||
if (pindex)
|
||||
pindex = m_chainman.ActiveChain().Next(pindex);
|
||||
pindex = m_chainman.ActiveChain().Next(*pindex);
|
||||
}
|
||||
|
||||
// we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
|
||||
std::vector<CBlock> vHeaders;
|
||||
int nLimit = m_opts.max_headers_result;
|
||||
LogDebug(BCLog::NET, "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom.GetId());
|
||||
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex))
|
||||
for (; pindex; pindex = m_chainman.ActiveChain().Next(*pindex))
|
||||
{
|
||||
vHeaders.emplace_back(pindex->GetBlockHeader());
|
||||
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
|
||||
|
||||
Reference in New Issue
Block a user