aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2023-11-02 13:26:57 +0100
committerVasil Dimov <vd@FreeBSD.org>2024-01-18 18:12:59 +0100
commit32a9f13cb805ecf6aebb5cf4e5d92b8a47c4548b (patch)
tree4ab4908ee7d63448a69c929c3cdb7a513ea538f6 /src/wallet/wallet.h
parent03c5b0064d4f766bc8dc6508773c7579e9ad39bc (diff)
downloadbitcoin-32a9f13cb805ecf6aebb5cf4e5d92b8a47c4548b.tar.xz
wallet: avoid returning a reference to vMasterKey after releasing the mutex that guards it
`CWallet::GetEncryptionKey()` would return a reference to the internal `CWallet::vMasterKey`, guarded by `CWallet::cs_wallet`, which is unsafe. Returning a copy would be a shorter solution, but could have security implications of the master key remaining somewhere in the memory even after `CWallet::Lock()` (the current calls to `CWallet::GetEncryptionKey()` are safe, but that is not future proof). So, instead of `EncryptSecret(m_storage.GetEncryptionKey(), ...)` change the `GetEncryptionKey()` method to provide the encryption key to a given callback: `m_storage.WithEncryptionKey([](const CKeyingMaterial& k) { EncryptSecret(k, ...); })` This silences the following (clang 18): ``` wallet/wallet.cpp:3520:12: error: returning variable 'vMasterKey' by reference requires holding mutex 'cs_wallet' [-Werror,-Wthread-safety-reference-return] 3520 | return vMasterKey; | ^ ```
Diffstat (limited to 'src/wallet/wallet.h')
-rw-r--r--src/wallet/wallet.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 487921443f..cc961068a5 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -962,7 +962,8 @@ public:
//! Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
void SetupLegacyScriptPubKeyMan();
- const CKeyingMaterial& GetEncryptionKey() const override;
+ bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
+
bool HasEncryptionKeys() const override;
/** Get last block processed height */