aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormuxator <antonio.muci@bancaditalia.it>2022-10-06 22:17:49 +0200
committerfanquake <fanquake@gmail.com>2022-10-28 18:14:51 +0800
commitd9f1c89e4967da4681f8c595b46cb1475e3d4897 (patch)
tree2d133599d6ae8aca156a7b11e152f8878e81d06e
parentbbea830a966a4a6045c7420743395d5253203f00 (diff)
downloadbitcoin-d9f1c89e4967da4681f8c595b46cb1475e3d4897.tar.xz
rpc: fix crash in deriveaddresses when derivation index is 2147483647
2147483647 is the maximum positive value of a signed int32, and - currently - the maximum value that the deriveaddresses bitcoin RPC call accepts as derivation index due to its input validation routines. Before this change, when the derivation index (and thus range_end) reached std::numeric_limits<int_32_t>::max(), the "i" variable in the for cycle (which is declared as int, and as such 32 bits in size on most platforms) would be incremented at the end of the first iteration and then warp back to -2147483648. This caused SIGABRT in bitcoind and a core dump. This change assigns "i" an explicit size of 64 bits on every platform, sidestepping the problem. Fixes #26274. Github-Pull: #26275 Rebased-From: addf9d6502db12cebcc5976df3111cac1a369b82
-rw-r--r--src/rpc/misc.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
index 2dace52777..5a8cc8fa78 100644
--- a/src/rpc/misc.cpp
+++ b/src/rpc/misc.cpp
@@ -284,7 +284,7 @@ static RPCHelpMan deriveaddresses()
UniValue addresses(UniValue::VARR);
- for (int i = range_begin; i <= range_end; ++i) {
+ for (int64_t i = range_begin; i <= range_end; ++i) {
FlatSigningProvider provider;
std::vector<CScript> scripts;
if (!desc->Expand(i, key_provider, scripts, provider)) {