Skip to content

Commit fa90777

Browse files
author
MarcoFalke
committed
rest: Reject truncated hex txid early in getutxos parsing
1 parent fab6ddb commit fa90777

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/rest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,14 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
792792
if (txid_out.size() != 2) {
793793
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
794794
}
795+
auto txid{Txid::FromHex(txid_out.at(0))};
795796
auto output{ToIntegral<uint32_t>(txid_out.at(1))};
796797

797-
if (!output || !IsHex(txid_out.at(0))) {
798+
if (!txid || !output) {
798799
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
799800
}
800801

801-
vOutPoints.emplace_back(TxidFromString(txid_out.at(0)), *output);
802+
vOutPoints.emplace_back(*txid, *output);
802803
}
803804

804805
if (vOutPoints.size() > 0)

test/functional/interface_rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def run_test(self):
208208
self.test_rest_request(f"/getutxos/{spending[0]}_+1", ret_type=RetType.OBJ, status=400)
209209
self.test_rest_request(f"/getutxos/{spending[0]}-+1", ret_type=RetType.OBJ, status=400)
210210
self.test_rest_request(f"/getutxos/{spending[0]}--1", ret_type=RetType.OBJ, status=400)
211+
self.test_rest_request(f"/getutxos/{spending[0]}aa-1234", ret_type=RetType.OBJ, status=400)
212+
self.test_rest_request(f"/getutxos/aa-1234", ret_type=RetType.OBJ, status=400)
211213

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

0 commit comments

Comments
 (0)