Skip to content

Commit 8615bfb

Browse files
committed
Merge pull request #4316
18116b0 Ignore too-long redeemScripts while loading wallet (Wladimir J. van der Laan)
2 parents 8047fb0 + 18116b0 commit 8615bfb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/wallet.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ bool CWallet::AddCScript(const CScript& redeemScript)
128128
return CWalletDB(strWalletFile).WriteCScript(Hash160(redeemScript), redeemScript);
129129
}
130130

131+
bool CWallet::LoadCScript(const CScript& redeemScript)
132+
{
133+
/* A sanity check was added in pull #3843 to avoid adding redeemScripts
134+
* that never can be redeemed. However, old wallets may still contain
135+
* these. Do not add them to the wallet and warn. */
136+
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
137+
{
138+
std::string strAddr = CBitcoinAddress(redeemScript.GetID()).ToString();
139+
LogPrintf("%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n",
140+
__func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr);
141+
return true;
142+
}
143+
144+
return CCryptoKeyStore::AddCScript(redeemScript);
145+
}
146+
131147
bool CWallet::Unlock(const SecureString& strWalletPassphrase)
132148
{
133149
CCrypter crypter;

src/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface
211211
// Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
212212
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
213213
bool AddCScript(const CScript& redeemScript);
214-
bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); }
214+
bool LoadCScript(const CScript& redeemScript);
215215

216216
/// Adds a destination data tuple to the store, and saves it to disk
217217
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);

0 commit comments

Comments
 (0)