Merge #12101: Clamp walletpassphrase timeout to 2^30 seconds and check its bounds
134cdc7Test walletpassphrase timeout bounds and clamping (Andrew Chow)0b63e3cClamp walletpassphrase timeout to 2^(30) seconds and check its bounds (Andrew Chow) Pull request description: Fixes #12100 Makes the timeout be clamped to 2^30 seconds to avoid the issue with sign flipping with large timeout values and thus relocking the wallet instantly. Unlocking for at most ~34 years should be sufficient. Also checks that the timeout is not negative to avoid instant relocks. Tree-SHA512: 426922f08c54e323d259e25dcdbebc2cd560708a65111ce6051493a7e7c61e79d9da1ea4026cc0d68807d728f5d7c0d7c58168c6ef4167b94cf6c2877af88794
This commit is contained in:
@@ -2283,7 +2283,8 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
|
||||
"This is needed prior to performing transactions related to private keys such as sending bitcoins\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"passphrase\" (string, required) The wallet passphrase\n"
|
||||
"2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
|
||||
"2. timeout (numeric, required) The time to keep the decryption key in seconds. Limited to at most 1073741824 (2^30) seconds.\n"
|
||||
" Any value greater than 1073741824 seconds will be set to 1073741824 seconds.\n"
|
||||
"\nNote:\n"
|
||||
"Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
|
||||
"time that overrides the old one.\n"
|
||||
@@ -2312,6 +2313,17 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
|
||||
// Alternately, find a way to make request.params[0] mlock()'d to begin with.
|
||||
strWalletPass = request.params[0].get_str().c_str();
|
||||
|
||||
// Get the timeout
|
||||
int64_t nSleepTime = request.params[1].get_int64();
|
||||
// Timeout cannot be negative, otherwise it will relock immediately
|
||||
if (nSleepTime < 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative.");
|
||||
}
|
||||
// Clamp timeout to 2^30 seconds
|
||||
if (nSleepTime > (int64_t)1 << 30) {
|
||||
nSleepTime = (int64_t)1 << 30;
|
||||
}
|
||||
|
||||
if (strWalletPass.length() > 0)
|
||||
{
|
||||
if (!pwallet->Unlock(strWalletPass)) {
|
||||
@@ -2325,7 +2337,6 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
|
||||
|
||||
pwallet->TopUpKeyPool();
|
||||
|
||||
int64_t nSleepTime = request.params[1].get_int64();
|
||||
pwallet->nRelockTime = GetTime() + nSleepTime;
|
||||
RPCRunLater(strprintf("lockwallet(%s)", pwallet->GetName()), boost::bind(LockWallet, pwallet), nSleepTime);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user