Skip to content

Commit c001992

Browse files
committed
Fix potential null dereferences
1 parent 3e55f13 commit c001992

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/miner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
145145

146146
LOCK2(cs_main, mempool.cs);
147147
CBlockIndex* pindexPrev = chainActive.Tip();
148+
assert(pindexPrev != nullptr);
148149
nHeight = pindexPrev->nHeight + 1;
149150

150151
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());

src/net_processing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {
281281
fUpdateConnectionTime = false;
282282
LOCK(cs_main);
283283
CNodeState *state = State(nodeid);
284+
assert(state != nullptr);
284285

285286
if (state->fSyncStarted)
286287
nSyncStarted--;
@@ -315,6 +316,7 @@ bool MarkBlockAsReceived(const uint256& hash) {
315316
std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
316317
if (itInFlight != mapBlocksInFlight.end()) {
317318
CNodeState *state = State(itInFlight->second.first);
319+
assert(state != nullptr);
318320
state->nBlocksInFlightValidHeaders -= itInFlight->second.second->fValidatedHeaders;
319321
if (state->nBlocksInFlightValidHeaders == 0 && itInFlight->second.second->fValidatedHeaders) {
320322
// Last validated block on the queue was received.

src/rpc/blockchain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
812812
static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
813813
{
814814
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
815+
assert(pcursor);
815816

816817
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
817818
stats.hashBlock = pcursor->GetBestBlock();
@@ -1514,6 +1515,8 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
15141515
pindex = chainActive.Tip();
15151516
}
15161517
}
1518+
1519+
assert(pindex != nullptr);
15171520

15181521
if (blockcount < 1 || blockcount >= pindex->nHeight) {
15191522
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 1 and the block's height");

src/validation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
251251
AssertLockHeld(mempool.cs);
252252

253253
CBlockIndex* tip = chainActive.Tip();
254+
assert(tip != nullptr);
255+
254256
CBlockIndex index;
255257
index.pprev = tip;
256258
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate

0 commit comments

Comments
 (0)