Skip to content

Commit 662d19f

Browse files
committed
[rpcwallet] Clamp walletpassphrase value at 100M seconds
Larger values seem to trigger a bug on macos+libevent (resulting in the rpc server stopping).
1 parent 1d54004 commit 662d19f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,8 +2349,7 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
23492349
"This is needed prior to performing transactions related to private keys such as sending bitcoins\n"
23502350
"\nArguments:\n"
23512351
"1. \"passphrase\" (string, required) The wallet passphrase\n"
2352-
"2. timeout (numeric, required) The time to keep the decryption key in seconds. Limited to at most 1073741824 (2^30) seconds.\n"
2353-
" Any value greater than 1073741824 seconds will be set to 1073741824 seconds.\n"
2352+
"2. timeout (numeric, required) The time to keep the decryption key in seconds; capped at 100000000 (~3 years).\n"
23542353
"\nNote:\n"
23552354
"Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
23562355
"time that overrides the old one.\n"
@@ -2383,9 +2382,10 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
23832382
if (nSleepTime < 0) {
23842383
throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative.");
23852384
}
2386-
// Clamp timeout to 2^30 seconds
2387-
if (nSleepTime > (int64_t)1 << 30) {
2388-
nSleepTime = (int64_t)1 << 30;
2385+
// Clamp timeout
2386+
constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug?
2387+
if (nSleepTime > MAX_SLEEP_TIME) {
2388+
nSleepTime = MAX_SLEEP_TIME;
23892389
}
23902390

23912391
if (strWalletPass.length() > 0)

test/functional/wallet_encryption.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ def run_test(self):
6464
assert_raises_rpc_error(-8, "Timeout cannot be negative.", self.nodes[0].walletpassphrase, passphrase2, -10)
6565
# Check the timeout
6666
# Check a time less than the limit
67-
expected_time = int(time.time()) + (1 << 30) - 600
68-
self.nodes[0].walletpassphrase(passphrase2, (1 << 30) - 600)
67+
MAX_VALUE = 100000000
68+
expected_time = int(time.time()) + MAX_VALUE - 600
69+
self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE - 600)
6970
actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
7071
assert_greater_than_or_equal(actual_time, expected_time)
7172
assert_greater_than(expected_time + 5, actual_time) # 5 second buffer
7273
# Check a time greater than the limit
73-
expected_time = int(time.time()) + (1 << 30) - 1
74-
self.nodes[0].walletpassphrase(passphrase2, (1 << 33))
74+
expected_time = int(time.time()) + MAX_VALUE - 1
75+
self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE + 1000)
7576
actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
7677
assert_greater_than_or_equal(actual_time, expected_time)
7778
assert_greater_than(expected_time + 5, actual_time) # 5 second buffer

0 commit comments

Comments
 (0)