Make an invalid addrIncoming so that old clients crash.

This prevents old clients from opening, and thus corrupting
or otherwise causing harm to encrypted wallets.
This commit is contained in:
Matt Corallo 2011-07-10 16:07:22 +02:00
parent 96f34cd5c4
commit 7414733bea
4 changed files with 15 additions and 4 deletions

View file

@ -828,7 +828,6 @@ bool CWalletDB::LoadWallet(CWallet* pwallet)
if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins; if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins;
#endif #endif
if (strKey == "nTransactionFee") ssValue >> nTransactionFee; if (strKey == "nTransactionFee") ssValue >> nTransactionFee;
if (strKey == "addrIncoming") ssValue >> addrIncoming;
if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors; if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors;
if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors; if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray; if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
@ -847,7 +846,6 @@ bool CWalletDB::LoadWallet(CWallet* pwallet)
printf("nFileVersion = %d\n", nFileVersion); printf("nFileVersion = %d\n", nFileVersion);
printf("fGenerateBitcoins = %d\n", fGenerateBitcoins); printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
printf("nTransactionFee = %"PRI64d"\n", nTransactionFee); printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
printf("addrIncoming = %s\n", addrIncoming.ToString().c_str());
printf("fMinimizeToTray = %d\n", fMinimizeToTray); printf("fMinimizeToTray = %d\n", fMinimizeToTray);
printf("fMinimizeOnClose = %d\n", fMinimizeOnClose); printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
printf("fUseProxy = %d\n", fUseProxy); printf("fUseProxy = %d\n", fUseProxy);

View file

@ -55,7 +55,6 @@ int64 nHPSTimerStart;
// Settings // Settings
int fGenerateBitcoins = false; int fGenerateBitcoins = false;
int64 nTransactionFee = 0; int64 nTransactionFee = 0;
CAddress addrIncoming;
int fLimitProcessors = false; int fLimitProcessors = false;
int nLimitProcessors = 1; int nLimitProcessors = 1;
int fMinimizeToTray = true; int fMinimizeToTray = true;

View file

@ -68,7 +68,6 @@ extern std::set<CWallet*> setpwalletRegistered;
// Settings // Settings
extern int fGenerateBitcoins; extern int fGenerateBitcoins;
extern int64 nTransactionFee; extern int64 nTransactionFee;
extern CAddress addrIncoming;
extern int fLimitProcessors; extern int fLimitProcessors;
extern int nLimitProcessors; extern int nLimitProcessors;
extern int fMinimizeToTray; extern int fMinimizeToTray;

View file

@ -108,6 +108,19 @@ bool CWallet::ChangeWalletPassphrase(const string& strOldWalletPassphrase, const
return false; return false;
} }
// This class implements an addrIncoming entry that causes pre-0.4
// clients to crash on startup if reading a private-key-encrypted wallet.
class CCorruptAddress
{
public:
IMPLEMENT_SERIALIZE
(
if (nType & SER_DISK)
READWRITE(nVersion);
)
};
bool CWallet::EncryptWallet(const string& strWalletPassphrase) bool CWallet::EncryptWallet(const string& strWalletPassphrase)
{ {
CRITICAL_BLOCK(cs_mapPubKeys) CRITICAL_BLOCK(cs_mapPubKeys)
@ -166,6 +179,8 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase)
if (fFileBacked) if (fFileBacked)
{ {
CCorruptAddress corruptAddress;
pwalletdbEncryption->WriteSetting("addrIncoming", corruptAddress);
if (!pwalletdbEncryption->TxnCommit()) if (!pwalletdbEncryption->TxnCommit())
exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet. exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet.