aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-09-06 23:53:55 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-09-06 23:54:06 +0200
commit6acdb1fab7703c644df2029a4ce05fb380b8a50b (patch)
tree98b7987f7264a4a6b93a161f9fbdcfc38a8dfc61
parentbc561b4b7d6a3f71649d37d5eb9047c29efa2b13 (diff)
parentc0019924406e1ce8368465c768de11019ad5eeed (diff)
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
-rw-r--r--src/miner.cpp1
-rw-r--r--src/net_processing.cpp2
-rw-r--r--src/rpc/blockchain.cpp3
-rw-r--r--src/validation.cpp2
4 files changed, 8 insertions, 0 deletions
diff --git a/src/miner.cpp b/src/miner.cpp
index f1942ec570..249ea172a6 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -145,6 +145,7 @@ std::unique_ptr<CBlockTemplate> 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 3ee4e5596b..cc44876712 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<uint256, std::pair<NodeId, std::list<QueuedBlock>::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 d131635067..46f4f16321 100644
--- a/src/rpc/blockchain.cpp
+++ b/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)
{
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
+ assert(pcursor);
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
stats.hashBlock = pcursor->GetBestBlock();
@@ -1517,6 +1518,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 d1ef11759c..d8788548ff 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -255,6 +255,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