From c0019924406e1ce8368465c768de11019ad5eeed 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/miner.cpp | 1 + src/net_processing.cpp | 2 ++ src/rpc/blockchain.cpp | 3 +++ src/validation.cpp | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index f1942ec57..249ea172a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -145,6 +145,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc LOCK2(cs_main, mempool.cs); CBlockIndex* pindexPrev = chainActive.Tip(); + assert(pindexPrev != nullptr); nHeight = pindexPrev->nHeight + 1; pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 596ae1139..9a446a930 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -281,6 +281,7 @@ void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) { fUpdateConnectionTime = false; LOCK(cs_main); CNodeState *state = State(nodeid); + assert(state != nullptr); if (state->fSyncStarted) nSyncStarted--; @@ -315,6 +316,7 @@ bool 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); state->nBlocksInFlightValidHeaders -= itInFlight->second.second->fValidatedHeaders; if (state->nBlocksInFlightValidHeaders == 0 && itInFlight->second.second->fValidatedHeaders) { // Last validated block on the queue was received. diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 34f553f3b..bcb179264 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -812,6 +812,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash, static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) { std::unique_ptr pcursor(view->Cursor()); + assert(pcursor); CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); stats.hashBlock = pcursor->GetBestBlock(); @@ -1514,6 +1515,8 @@ UniValue getchaintxstats(const JSONRPCRequest& request) pindex = chainActive.Tip(); } } + + assert(pindex != nullptr); if (blockcount < 1 || blockcount >= pindex->nHeight) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 1 and the block's height"); diff --git a/src/validation.cpp b/src/validation.cpp index d1a8b8460..51dad02e8 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -251,6 +251,8 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool AssertLockHeld(mempool.cs); CBlockIndex* tip = chainActive.Tip(); + assert(tip != nullptr); + CBlockIndex index; index.pprev = tip; // CheckSequenceLocks() uses chainActive.Height()+1 to evaluate