From e51e4ee6749ddb49953bb8c5af8173ac7f5ca511 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 6 Oct 2021 19:48:14 +0200 Subject: [PATCH] Merge bitcoin-core/gui#446: RPCConsole: Throw when overflowing size_t type for array indices faa5e171e6bdb8f3b4027a3f06497f0de5abf766 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 faa5e171e6bdb8f3b4027a3f06497f0de5abf766 shaavan: ACK faa5e17 Tree-SHA512: ddff39aae1c15db45928b110a9f1c42eadc5404cdfa89d67ccffc4c6af24091967d43c068ce9e0c1b863cfc4eb5b4f12373a73756a9474f8294e8a44aabc28d8 --- src/qt/rpcconsole.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index c6ae2e9e89..d98a03a633 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -225,10 +225,11 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes UniValue subelement; if (lastResult.isArray()) { - for(char argch: curarg) - if (!IsDigit(argch)) - throw std::runtime_error("Invalid result query"); - subelement = lastResult[LocaleIndependentAtoi(curarg)]; + const auto parsed{ToIntegral(curarg)}; + if (!parsed) { + throw std::runtime_error("Invalid result query"); + } + subelement = lastResult[parsed.value()]; } else if (lastResult.isObject()) subelement = find_value(lastResult, curarg);