From 732bb9d7ee619f548b4a1f848b4e4d18b67c14d8 Mon Sep 17 00:00:00 2001 From: MeshCollider Date: Wed, 23 Aug 2017 19:47:56 +1200 Subject: [PATCH] Fix potential null dereferences --- src/net_processing.cpp | 11 ++++++----- src/rpc/blockchain.cpp | 2 ++ src/validation.cpp | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 8121f975153a9..cd2f91694fcd1 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -232,7 +232,7 @@ CNodeState* State(NodeId pnode) { std::map::iterator it = mapNodeState.find(pnode); if (it == mapNodeState.end()) - return NULL; + return nullptr; return &it->second; } @@ -272,6 +272,7 @@ void MarkBlockAsReceived(const uint256& hash) std::map::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash); if (itInFlight != mapBlocksInFlight.end()) { CNodeState* state = State(itInFlight->second.first); + assert(state != nullptr); nQueuedValidatedHeaders -= itInFlight->second.second->fValidatedHeaders; state->vBlocksInFlight.erase(itInFlight->second.second); state->nBlocksInFlight--; @@ -284,7 +285,7 @@ void MarkBlockAsReceived(const uint256& hash) void MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr) { CNodeState* state = State(nodeid); - assert(state != NULL); + assert(state != nullptr); // Make sure it's not listed somewhere already. MarkBlockAsReceived(hash); @@ -300,7 +301,7 @@ void MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* void ProcessBlockAvailability(NodeId nodeid) { CNodeState* state = State(nodeid); - assert(state != NULL); + assert(state != nullptr); if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); @@ -316,7 +317,7 @@ void ProcessBlockAvailability(NodeId nodeid) void UpdateBlockAvailability(NodeId nodeid, const uint256& hash) { CNodeState* state = State(nodeid); - assert(state != NULL); + assert(state != nullptr); ProcessBlockAvailability(nodeid); @@ -340,7 +341,7 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector pcursor(view->Cursor()); + assert(pcursor); CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); stats.hashBlock = pcursor->GetBestBlock(); @@ -864,6 +865,7 @@ UniValue gettxout(const JSONRPCRequest& request) BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex* pindex = it->second; + assert(pindex != nullptr); ret.pushKV("bestblock", pindex->GetBlockHash().GetHex()); if (coin.nHeight == MEMPOOL_HEIGHT) { ret.pushKV("confirmations", 0); diff --git a/src/validation.cpp b/src/validation.cpp index 1d435eaa8e5fe..bdba41a251442 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1870,6 +1870,7 @@ void static UpdateTip(CBlockIndex* pindexNew) } const CBlockIndex* pChainTip = chainActive.Tip(); + assert(pChainTip != nullptr); LogPrintf("%s: new best=%s height=%d version=%d log2_work=%.16f tx=%lu date=%s progress=%f cache=%.1fMiB(%utxo) evodb_cache=%.1fMiB\n", __func__, pChainTip->GetBlockHash().GetHex(), pChainTip->nHeight, pChainTip->nVersion, log(pChainTip->nChainWork.getdouble()) / log(2.0), (unsigned long)pChainTip->nChainTx,