Browse Source

Merge #11238: Add assertions before potential null deferences

c00199244 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
0.16
Wladimir J. van der Laan 7 years ago
parent
commit
6acdb1fab7
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 1
      src/miner.cpp
  2. 2
      src/net_processing.cpp
  3. 3
      src/rpc/blockchain.cpp
  4. 2
      src/validation.cpp

1
src/miner.cpp

@ -145,6 +145,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
LOCK2(cs_main, mempool.cs); LOCK2(cs_main, mempool.cs);
CBlockIndex* pindexPrev = chainActive.Tip(); CBlockIndex* pindexPrev = chainActive.Tip();
assert(pindexPrev != nullptr);
nHeight = pindexPrev->nHeight + 1; nHeight = pindexPrev->nHeight + 1;
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());

2
src/net_processing.cpp

@ -281,6 +281,7 @@ void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {
fUpdateConnectionTime = false; fUpdateConnectionTime = false;
LOCK(cs_main); LOCK(cs_main);
CNodeState *state = State(nodeid); CNodeState *state = State(nodeid);
assert(state != nullptr);
if (state->fSyncStarted) if (state->fSyncStarted)
nSyncStarted--; nSyncStarted--;
@ -315,6 +316,7 @@ bool MarkBlockAsReceived(const uint256& hash) {
std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash); std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
if (itInFlight != mapBlocksInFlight.end()) { if (itInFlight != mapBlocksInFlight.end()) {
CNodeState *state = State(itInFlight->second.first); CNodeState *state = State(itInFlight->second.first);
assert(state != nullptr);
state->nBlocksInFlightValidHeaders -= itInFlight->second.second->fValidatedHeaders; state->nBlocksInFlightValidHeaders -= itInFlight->second.second->fValidatedHeaders;
if (state->nBlocksInFlightValidHeaders == 0 && itInFlight->second.second->fValidatedHeaders) { if (state->nBlocksInFlightValidHeaders == 0 && itInFlight->second.second->fValidatedHeaders) {
// Last validated block on the queue was received. // Last validated block on the queue was received.

3
src/rpc/blockchain.cpp

@ -814,6 +814,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
{ {
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
assert(pcursor);
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
stats.hashBlock = pcursor->GetBestBlock(); stats.hashBlock = pcursor->GetBestBlock();
@ -1518,6 +1519,8 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
} }
} }
assert(pindex != nullptr);
if (blockcount < 1 || blockcount >= pindex->nHeight) { if (blockcount < 1 || blockcount >= pindex->nHeight) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 1 and the block's height"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 1 and the block's height");
} }

2
src/validation.cpp

@ -255,6 +255,8 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
AssertLockHeld(mempool.cs); AssertLockHeld(mempool.cs);
CBlockIndex* tip = chainActive.Tip(); CBlockIndex* tip = chainActive.Tip();
assert(tip != nullptr);
CBlockIndex index; CBlockIndex index;
index.pprev = tip; index.pprev = tip;
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate // CheckSequenceLocks() uses chainActive.Height()+1 to evaluate

Loading…
Cancel
Save