Skip to content

Commit 7962c97

Browse files
author
MarcoFalke
committed
Merge bitcoin-core#446: RPCConsole: Throw when overflowing size_t type for array indices
faa5e17 RPCConsole: Throw when overflowing size_t type for array indices (MarcoFalke) Pull request description: To test: -> `getblock(getbestblockhash(), 1)[tx][22222222222222222222222222222]` Before: <- `868693731dea69a197c13c2cfaa41c9f78fcdeb8ab8e9f8cdf2c9025147ee7d1` (hash of the coinbase tx) After: <- `Error: Invalid result query` ACKs for top commit: jarolrod: ACK faa5e17 shaavan: ACK faa5e17 Tree-SHA512: ddff39aae1c15db45928b110a9f1c42eadc5404cdfa89d67ccffc4c6af24091967d43c068ce9e0c1b863cfc4eb5b4f12373a73756a9474f8294e8a44aabc28d8
2 parents bb8550b + faa5e17 commit 7962c97

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/qt/rpcconsole.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,11 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
247247
UniValue subelement;
248248
if (lastResult.isArray())
249249
{
250-
for(char argch: curarg)
251-
if (!IsDigit(argch))
252-
throw std::runtime_error("Invalid result query");
253-
subelement = lastResult[LocaleIndependentAtoi<int>(curarg)];
250+
const auto parsed{ToIntegral<size_t>(curarg)};
251+
if (!parsed) {
252+
throw std::runtime_error("Invalid result query");
253+
}
254+
subelement = lastResult[parsed.value()];
254255
}
255256
else if (lastResult.isObject())
256257
subelement = find_value(lastResult, curarg);

0 commit comments

Comments
 (0)