diff options
Diffstat (limited to 'src/wallet/db.cpp')
-rw-r--r-- | src/wallet/db.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 50b0f40a6a..c906785e9e 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); @@ -193,24 +198,35 @@ bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vector<C // Format of bdb dump is ascii lines: // header lines... // HEADER=END - // hexadecimal key - // hexadecimal value - // ... repeated + // hexadecimal key + // hexadecimal value + // ... repeated // 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); } |