[rpc]Avoid possibility of NULL pointer dereference in getblockchaininfo(...) #10619

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+2 −0
Split
View
@@ -1165,6 +1165,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
+ HelpExampleRpc("getblockchaininfo", "")
);
+ assert(chainActive.Tip() && "An empty blockchain should not be possible here.");
@TheBlueMatt

TheBlueMatt Jul 25, 2017

Contributor

This needs to be inside the cs_main, I'd think.

LOCK(cs_main);
UniValue obj(UniValue::VOBJ);
@@ -1196,6 +1197,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))
block = block->pprev;
+ assert(block && "An empty blockchain should not be possible here.");
obj.push_back(Pair("pruneheight", block->nHeight));
}
return obj;