mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Merge #7537: wallet: Warn on unexpected EOF while salvaging wallet
ca8fb59
wallet: Warn on unexpected EOF while salvaging wallet (Wladimir J. van der Laan)
This commit is contained in:
parent
5390a1a0a9
commit
74eda87591
@ -165,6 +165,11 @@ CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, bool (*recoverFu
|
|||||||
return (fRecovered ? RECOVER_OK : RECOVER_FAIL);
|
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)
|
bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vector<CDBEnv::KeyValPair>& vResult)
|
||||||
{
|
{
|
||||||
LOCK(cs_db);
|
LOCK(cs_db);
|
||||||
@ -199,18 +204,29 @@ bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vector<C
|
|||||||
// DATA=END
|
// DATA=END
|
||||||
|
|
||||||
string strLine;
|
string strLine;
|
||||||
while (!strDump.eof() && strLine != "HEADER=END")
|
while (!strDump.eof() && strLine != HEADER_END)
|
||||||
getline(strDump, strLine); // Skip past header
|
getline(strDump, strLine); // Skip past header
|
||||||
|
|
||||||
std::string keyHex, valueHex;
|
std::string keyHex, valueHex;
|
||||||
while (!strDump.eof() && keyHex != "DATA=END") {
|
while (!strDump.eof() && keyHex != DATA_END) {
|
||||||
getline(strDump, keyHex);
|
getline(strDump, keyHex);
|
||||||
if (keyHex != "DATA=END") {
|
if (keyHex != DATA_END) {
|
||||||
|
if (strDump.eof())
|
||||||
|
break;
|
||||||
getline(strDump, valueHex);
|
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)));
|
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);
|
return (result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user