Skip to content

Commit b2bd17d

Browse files
authored
Merge pull request #1459 from jamescowens/fix_walletpassphrase_unlock_interval_bug
Constrain walletpassphrase to 10000000 seconds
2 parents 6c540cc + ec025e0 commit b2bd17d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/rpcwallet.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,9 +1955,19 @@ UniValue walletpassphrase(const UniValue& params, bool fHelp)
19551955
if (!pwalletMain->IsLocked())
19561956
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked, use walletlock first if need to change unlock settings.");
19571957

1958+
// Adapted from Bitcoin (20190511)...
1959+
// Get the timeout
19581960
int64_t nSleepTime = params[1].get_int64();
1959-
if (nSleepTime <= 0 || nSleepTime >= std::numeric_limits<int64_t>::max() / 1000000000)
1960-
throw runtime_error("timeout is out of bounds");
1961+
// Timeout cannot be negative or zero, otherwise it will relock immediately.
1962+
if (nSleepTime <= 0) {
1963+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative or zero.");
1964+
}
1965+
// Clamp timeout
1966+
constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug?
1967+
if (nSleepTime > MAX_SLEEP_TIME) {
1968+
nSleepTime = MAX_SLEEP_TIME;
1969+
LogPrintf("WARN: walletpassphrase: timeout is too large. Set to limit of 10000000 seconds.");
1970+
}
19611971

19621972
// Note that the walletpassphrase is stored in params[0] which is not mlock()ed
19631973
SecureString strWalletPass;

0 commit comments

Comments
 (0)