wallet: Fix use-after-free in WalletBatch::EraseRecords

Github-Pull: #29176
Rebased-From: faebf1df2a
This commit is contained in:
MarcoFalke 2024-01-04 12:18:07 +01:00 committed by fanquake
parent 40252e184e
commit ccf00b1e6e
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -1401,13 +1401,13 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
} }
// Make a copy of key to avoid data being deleted by the following read of the type // Make a copy of key to avoid data being deleted by the following read of the type
Span key_data{key}; const SerializeData key_data{key.begin(), key.end()};
std::string type; std::string type;
key >> type; key >> type;
if (types.count(type) > 0) { if (types.count(type) > 0) {
if (!m_batch->Erase(key_data)) { if (!m_batch->Erase(Span{key_data})) {
cursor.reset(nullptr); cursor.reset(nullptr);
m_batch->TxnAbort(); m_batch->TxnAbort();
return false; // erase failed return false; // erase failed