File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff 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;
You can’t perform that action at this time.
0 commit comments