From 00d832756cd1c4574774497dc1232101bea5db96 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 11 Mar 2012 17:57:44 -0400 Subject: [PATCH 1/3] Print wallet load errors (to debug.log) --- src/init.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 079e67b9363..2dccc81bf56 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -398,12 +398,14 @@ bool AppInit2(int argc, char* argv[]) else if (nLoadWalletRet == DB_NEED_REWRITE) { strErrors += _("Wallet needed to be rewritten: restart Bitcoin to complete \n"); + printf("%s", strErrors.c_str()); wxMessageBox(strErrors, "Bitcoin", wxOK | wxICON_ERROR); return false; } else strErrors += _("Error loading wallet.dat \n"); } + printf("%s", strErrors.c_str()); printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart); RegisterWallet(pwalletMain); From 1194f003504fa6e9d9f59012ec736ebc7c231360 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 11 Mar 2012 18:07:40 -0400 Subject: [PATCH 2/3] Print more diagnostic info for the various DB_CORRUPT conditions --- src/db.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 783b0799639..7f9439bf745 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -798,7 +798,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) // Get cursor Dbc* pcursor = GetCursor(); if (!pcursor) + { + printf("Error getting wallet database cursor\n"); return DB_CORRUPT; + } loop { @@ -809,7 +812,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) if (ret == DB_NOTFOUND) break; else if (ret != 0) + { + printf("Error reading next record from wallet database\n"); return DB_CORRUPT; + } // Unserialize // Taking advantage of the fact that pair serialization @@ -879,19 +885,38 @@ int CWalletDB::LoadWallet(CWallet* pwallet) CPrivKey pkey; ssValue >> pkey; key.SetPrivKey(pkey); - if (key.GetPubKey() != vchPubKey || !key.IsValid()) + if (key.GetPubKey() != vchPubKey) + { + printf("Error reading wallet database: CPrivKey pubkey inconsistency\n"); return DB_CORRUPT; + } + if (!key.IsValid()) + { + printf("Error reading wallet database: invalid CPrivKey\n"); + return DB_CORRUPT; + } } else { CWalletKey wkey; ssValue >> wkey; key.SetPrivKey(wkey.vchPrivKey); - if (key.GetPubKey() != vchPubKey || !key.IsValid()) + if (key.GetPubKey() != vchPubKey) + { + printf("Error reading wallet database: CWalletKey pubkey inconsistency\n"); return DB_CORRUPT; + } + if (!key.IsValid()) + { + printf("Error reading wallet database: invalid CWalletKey\n"); + return DB_CORRUPT; + } } if (!pwallet->LoadKey(key)) + { + printf("Error reading wallet database: LoadKey failed\n"); return DB_CORRUPT; + } } else if (strType == "mkey") { @@ -900,7 +925,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) CMasterKey kMasterKey; ssValue >> kMasterKey; if(pwallet->mapMasterKeys.count(nID) != 0) + { + printf("Error reading wallet database: duplicate CMasterKey id %u\n", nID); return DB_CORRUPT; + } pwallet->mapMasterKeys[nID] = kMasterKey; if (pwallet->nMasterKeyMaxID < nID) pwallet->nMasterKeyMaxID = nID; @@ -912,7 +940,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) vector vchPrivKey; ssValue >> vchPrivKey; if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey)) + { + printf("Error reading wallet database: LoadCryptedKey failed\n"); return DB_CORRUPT; + } fIsEncrypted = true; } else if (strType == "defaultkey") From 0e6c6e3fd1ab971c652e48fa04bac097e44e76fe Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 18 Feb 2012 13:32:25 +0100 Subject: [PATCH 3/3] Workaround for BN_bn2mpi reading/writing out of bounds When OpenSSL's BN_bn2mpi is passed a buffer of size 4, valgrind reports reading/writing one byte past it. I am unable to find evidence of this behaviour in BN_bn2mpi's source code, so it may be a spurious warning. However, this change is harmless, as only the bignum with value 0 results in an mpi serialization of size 4. --- src/bignum.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bignum.h b/src/bignum.h index 1a2406b9358..6e8d3cb8aba 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -243,7 +243,7 @@ public: std::vector getvch() const { unsigned int nSize = BN_bn2mpi(this, NULL); - if (nSize < 4) + if (nSize <= 4) return std::vector(); std::vector vch(nSize); BN_bn2mpi(this, &vch[0]);