Add missing cs_main locks when calling blockToJSON/blockheaderToJSON

zcash: cherry picked from commit a9b6ba0b7cd27a64307987afaab7f60bf9b4a15b
zcash: https://github.com/bitcoin/bitcoin/pull/11618
This commit is contained in:
practicalswift 2017-11-06 23:20:43 +01:00 committed by Larry Ruane
parent 29eb55cc28
commit d8926263b7
2 changed files with 12 additions and 3 deletions

View File

@ -173,8 +173,11 @@ static bool rest_headers(HTTPRequest* req,
}
case RF_JSON: {
UniValue jsonHeaders(UniValue::VARR);
for (const CBlockIndex *pindex : headers) {
jsonHeaders.push_back(blockheaderToJSON(pindex));
{
LOCK(cs_main);
for (const CBlockIndex *pindex : headers) {
jsonHeaders.push_back(blockheaderToJSON(pindex));
}
}
string strJSON = jsonHeaders.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
@ -238,7 +241,11 @@ static bool rest_block(HTTPRequest* req,
}
case RF_JSON: {
UniValue objBlock = blockToJSON(block, pblockindex, showTxDetails);
UniValue objBlock;
{
LOCK(cs_main);
objBlock = blockToJSON(block, pblockindex, showTxDetails);
}
string strJSON = objBlock.write() + "\n";
req->WriteHeader("Content-Type", "application/json");
req->WriteReply(HTTP_OK, strJSON);

View File

@ -103,6 +103,7 @@ static UniValue ValuePoolDesc(
UniValue blockheaderToJSON(const CBlockIndex* blockindex)
{
AssertLockHeld(cs_main);
UniValue result(UniValue::VOBJ);
result.pushKV("hash", blockindex->GetBlockHash().GetHex());
int confirmations = -1;
@ -220,6 +221,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
{
AssertLockHeld(cs_main);
UniValue result(UniValue::VOBJ);
result.pushKV("hash", block.GetHash().GetHex());
int confirmations = -1;