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

fa165e9545 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 fa165e9545
  practicalswift:
    cr ACK fa165e9545
  theStack:
    Code-review ACK fa165e9545

Tree-SHA512: b87f01431ca0b971ff84610022da8679d3c33470b88cfc3f4a337e6e176a0455715588aefd40e8e2bbe7459d902dc89d7bfe34e7fd66755f631cc18dc039fa2f
This commit is contained in:
fanquake 2021-10-11 08:45:11 +08:00
commit 01129ca372
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
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

@ -42,7 +42,6 @@ export LC_ALL=C
# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent snprintf with strprintf.
KNOWN_VIOLATIONS=(
"src/bitcoin-tx.cpp.*stoul"
"src/dbwrapper.cpp.*stoul"
"src/dbwrapper.cpp:.*vsnprintf"
"src/rest.cpp:.*strtol"
"src/test/dbwrapper_tests.cpp:.*snprintf"