Skip to content

Commit 6acdb1f

Browse files
committed
Merge #11238: Add assertions before potential null deferences
c001992 Fix potential null dereferences (MeshCollider) Pull request description: Picked up by the static analyzer [Facebook Infer](http://fbinfer.com/) which I was playing around with for another research project. Just adding some asserts before dereferencing potentially null pointers. Tree-SHA512: 9c01dab2d21bce75c7c7ef867236654ab538318a1fb39f96f09cdd2382a05be1a6b2db0a1169a94168864e82ffeae0686a383db6eba799742bdd89c37ac74397
2 parents bc561b4 + c001992 commit 6acdb1f

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
@@ -814,6 +814,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
814814
static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
815815
{
816816
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
817+
assert(pcursor);
817818

818819
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
819820
stats.hashBlock = pcursor->GetBestBlock();
@@ -1517,6 +1518,8 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
15171518
pindex = chainActive.Tip();
15181519
}
15191520
}
1521+
1522+
assert(pindex != nullptr);
15201523

15211524
if (blockcount < 1 || blockcount >= pindex->nHeight) {
15221525
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
@@ -255,6 +255,8 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
255255
AssertLockHeld(mempool.cs);
256256

257257
CBlockIndex* tip = chainActive.Tip();
258+
assert(tip != nullptr);
259+
258260
CBlockIndex index;
259261
index.pprev = tip;
260262
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate

0 commit comments

Comments
 (0)