Merge bitcoin/bitcoin#23214: Replace stoul with ToIntegral in dbwrapper

fa165e954579436fe4b636e4222d8ce0c1269786 Replace stoul with ToIntegral in dbwrapper (MarcoFalke)

Pull request description:

  The string is created with `%llu`. See: 7fcf53f7b4/src/leveldb/db/db_impl.cc (L1436-L1437)

  So it seems odd to silently accept when parsing: whitespace, a sign character, trailing chars, overflow, ....

  Fix that by using the stricter ToIntegral.

ACKs for top commit:
  laanwj:
    Code review ACK fa165e954579436fe4b636e4222d8ce0c1269786
  practicalswift:
    cr ACK fa165e954579436fe4b636e4222d8ce0c1269786
  theStack:
    Code-review ACK fa165e954579436fe4b636e4222d8ce0c1269786

Tree-SHA512: b87f01431ca0b971ff84610022da8679d3c33470b88cfc3f4a337e6e176a0455715588aefd40e8e2bbe7459d902dc89d7bfe34e7fd66755f631cc18dc039fa2f
This commit is contained in:
fanquake 2021-10-11 08:45:11 +08:00 committed by PastaPastaPasta
parent 3233445aa7
commit 0c52db6174
2 changed files with 5 additions and 4 deletions

View File

@ -197,13 +197,15 @@ bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
return true;
}
size_t CDBWrapper::DynamicMemoryUsage() const {
size_t CDBWrapper::DynamicMemoryUsage() const
{
std::string memory;
if (!pdb->GetProperty("leveldb.approximate-memory-usage", &memory)) {
std::optional<size_t> parsed;
if (!pdb->GetProperty("leveldb.approximate-memory-usage", &memory) || !(parsed = ToIntegral<size_t>(memory))) {
LogPrint(BCLog::LEVELDB, "Failed to get approximate-memory-usage property\n");
return 0;
}
return stoul(memory);
return parsed.value();
}
// Prefixed with null character to avoid collisions with other keys

View File

@ -43,7 +43,6 @@ export LC_ALL=C
KNOWN_VIOLATIONS=(
"src/bitcoin-tx.cpp.*stoul"
"src/dbwrapper.cpp.*stoul"
"src/dbwrapper.cpp:.*vsnprintf"
"src/rest.cpp:.*strtol"
"src/statsd_client.cpp:.*snprintf"