Skip to content

Commit d9f1c89

Browse files
muxatorfanquake
muxator
authored andcommitted
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: addf9d6
1 parent bbea830 commit d9f1c89

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/rpc/misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static RPCHelpMan deriveaddresses()
284284

285285
UniValue addresses(UniValue::VARR);
286286

287-
for (int i = range_begin; i <= range_end; ++i) {
287+
for (int64_t i = range_begin; i <= range_end; ++i) {
288288
FlatSigningProvider provider;
289289
std::vector<CScript> scripts;
290290
if (!desc->Expand(i, key_provider, scripts, provider)) {

0 commit comments

Comments
 (0)