Skip to content

Commit fab54db

Browse files
author
MarcoFalke
committed
rest: Reject negative outpoint index in getutxos parsing
1 parent 4d6af61 commit fab54db

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/rest.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -788,14 +788,15 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
788788

789789
for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
790790
{
791-
int32_t nOutput;
792791
std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
793792
std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1);
793+
auto output{ToIntegral<uint32_t>(strOutput)};
794794

795-
if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
795+
if (!output || !IsHex(strTxid)) {
796796
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
797+
}
797798

798-
vOutPoints.emplace_back(TxidFromString(strTxid), (uint32_t)nOutput);
799+
vOutPoints.emplace_back(TxidFromString(strTxid), *output);
799800
}
800801

801802
if (vOutPoints.size() > 0)

test/functional/interface_rest.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,13 @@ def run_test(self):
201201
json_obj = self.test_rest_request(f"/getutxos/checkmempool/{spending[0]}-{spending[1]}")
202202
assert_equal(len(json_obj['utxos']), 1)
203203

204-
# Do some invalid requests
204+
self.log.info("Check some invalid requests")
205205
self.test_rest_request("/getutxos", http_method='POST', req_type=ReqType.JSON, body='{"checkmempool', status=400, ret_type=RetType.OBJ)
206206
self.test_rest_request("/getutxos", http_method='POST', req_type=ReqType.BIN, body='{"checkmempool', status=400, ret_type=RetType.OBJ)
207207
self.test_rest_request("/getutxos/checkmempool", http_method='POST', req_type=ReqType.JSON, status=400, ret_type=RetType.OBJ)
208+
self.test_rest_request(f"/getutxos/{spending[0]}_+1", ret_type=RetType.OBJ, status=400)
209+
self.test_rest_request(f"/getutxos/{spending[0]}-+1", ret_type=RetType.OBJ, status=400)
210+
self.test_rest_request(f"/getutxos/{spending[0]}--1", ret_type=RetType.OBJ, status=400)
208211

209212
# Test limits
210213
long_uri = '/'.join([f"{txid}-{n_}" for n_ in range(20)])

0 commit comments

Comments
 (0)