aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/db.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-02-15 16:09:13 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-02-15 16:35:12 +0100
commitca8fb59ae14b4140e24c4d12c7b87597fd80a932 (patch)
tree37236fe87af43f6d06eb885656c7a46e5556ef2a /src/wallet/db.cpp
parentbf1e113311fe225c9a3a78f9d0fb5e43974573b7 (diff)
wallet: Warn on unexpected EOF while salvaging wallet
Check for EOF before every getline, and warn when reading gets to EOF before the end of the data. Stricter error checking could shed more light on issues such as #7463 and #7379.
Diffstat (limited to 'src/wallet/db.cpp')
-rw-r--r--src/wallet/db.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 50b0f40a6a..0b07cddde4 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -165,6 +165,11 @@ CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, bool (*recoverFu
return (fRecovered ? RECOVER_OK : RECOVER_FAIL);
}
+/* End of headers, beginning of key/value data */
+static const char *HEADER_END = "HEADER=END";
+/* End of key/value data */
+static const char *DATA_END = "DATA=END";
+
bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vector<CDBEnv::KeyValPair>& vResult)
{
LOCK(cs_db);
@@ -199,18 +204,29 @@ bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vector<C
// DATA=END
string strLine;
- while (!strDump.eof() && strLine != "HEADER=END")
+ while (!strDump.eof() && strLine != HEADER_END)
getline(strDump, strLine); // Skip past header
std::string keyHex, valueHex;
- while (!strDump.eof() && keyHex != "DATA=END") {
+ while (!strDump.eof() && keyHex != DATA_END) {
getline(strDump, keyHex);
- if (keyHex != "DATA=END") {
+ if (keyHex != DATA_END) {
+ if (strDump.eof())
+ break;
getline(strDump, valueHex);
+ if (valueHex == DATA_END) {
+ LogPrintf("CDBEnv::Salvage: WARNING: Number of keys in data does not match number of values.\n");
+ break;
+ }
vResult.push_back(make_pair(ParseHex(keyHex), ParseHex(valueHex)));
}
}
+ if (keyHex != DATA_END) {
+ LogPrintf("CDBEnv::Salvage: WARNING: Unexpected end of file while reading salvage output.\n");
+ return false;
+ }
+
return (result == 0);
}