Skip to content

Commit 3a11adc

Browse files
committed
Zero out wallet master key upon lock
When an encrypted wallet is locked (for instance via the RPC `walletlock`), the docs indicate that the key is removed from memory. However, the vector (with a secure allocator) is merely cleared. This allows the key to persist indefinitely in memory. Instead, manually fill the bytes with zeroes before clearing.
1 parent b92d609 commit 3a11adc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/wallet/wallet.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <script/descriptor.h>
2727
#include <script/script.h>
2828
#include <script/signingprovider.h>
29+
#include <support/cleanse.h>
2930
#include <txmempool.h>
3031
#include <util/bip32.h>
3132
#include <util/check.h>
@@ -3407,7 +3408,10 @@ bool CWallet::Lock()
34073408

34083409
{
34093410
LOCK(cs_wallet);
3410-
vMasterKey.clear();
3411+
if (!vMasterKey.empty()) {
3412+
memory_cleanse(vMasterKey.data(), vMasterKey.size() * sizeof(decltype(vMasterKey)::value_type));
3413+
vMasterKey.clear();
3414+
}
34113415
}
34123416

34133417
NotifyStatusChanged(this);

0 commit comments

Comments
 (0)