Skip to content

Commit d80348c

Browse files
committed
Merge bitcoin/bitcoin#27853: rest: bugfix, fix crash error when calling /deploymentinfo
7d452d8 test: add coverage for `/deploymentinfo` passing a blockhash (brunoerg) ce887ea rest: bugfix, fix crash error when calling `/deploymentinfo` (brunoerg) Pull request description: Calling `/deploymentinfo` passing a valid blockhash makes bitcoind to crash. It happens because we're pushing a JSON value of type array when it expects type object. See: ```cpp jsonRequest.params = UniValue(UniValue::VARR); ``` ```cpp jsonRequest.params.pushKV("blockhash", hash_str); ``` This PR fixes it by changing `pushKV` to `push_back` and adds more test coverage. ACKs for top commit: achow101: ACK 7d452d8 stickies-v: ACK 7d452d8 Tree-SHA512: f01551e556aba2380c3eaed0bc59057304302c202d317d7c1eec5f7ef839851f672aed80819a8719cb1cbbad2aad735d6d44314ac7d6d98bff8217f5a16c312b
2 parents c92fd63 + 7d452d8 commit d80348c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/rest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const
627627
return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
628628
}
629629

630-
jsonRequest.params.pushKV("blockhash", hash_str);
630+
jsonRequest.params.push_back(hash_str);
631631
}
632632

633633
req->WriteHeader("Content-Type", "application/json");

test/functional/interface_rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ def run_test(self):
421421
deployment_info = self.nodes[0].getdeploymentinfo()
422422
assert_equal(deployment_info, self.test_rest_request('/deploymentinfo'))
423423

424+
previous_bb_hash = self.nodes[0].getblockhash(self.nodes[0].getblockcount() - 1)
425+
deployment_info = self.nodes[0].getdeploymentinfo(previous_bb_hash)
426+
assert_equal(deployment_info, self.test_rest_request(f"/deploymentinfo/{previous_bb_hash}"))
427+
424428
non_existing_blockhash = '42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4'
425429
resp = self.test_rest_request(f'/deploymentinfo/{non_existing_blockhash}', ret_type=RetType.OBJ, status=400)
426430
assert_equal(resp.read().decode('utf-8').rstrip(), "Block not found")

0 commit comments

Comments
 (0)