Skip to content

Commit d84f736

Browse files
committed
Merge bitcoin/bitcoin#29176: wallet: Fix use-after-free in WalletBatch::EraseRecords
faebf1d wallet: Fix use-after-free in WalletBatch::EraseRecords (MarcoFalke) Pull request description: Creating a copy of the pointer to the underlying data of the stream is not enough to copy the data. Currently this happens to work sometimes, because the stream may not immediately free unused memory. However, there is no guarantee by the stream interface to always behave this way. Also, if `vector::clear` is called on the underlying memory, any pointers to it are invalid. Fix this, by creating a full copy of all bytes. ACKs for top commit: achow101: ACK faebf1d Tree-SHA512: 79ede9bc16cf257609545597bc6d9623ceead4531780ea6037cc5684aa3a7c7d80601354d315358defe47193f978a8ce40c5dc4637e32936c76157679b549ac5
2 parents 65c05db + faebf1d commit d84f736

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/wallet/walletdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,13 +1401,13 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
14011401
}
14021402

14031403
// Make a copy of key to avoid data being deleted by the following read of the type
1404-
Span key_data{key};
1404+
const SerializeData key_data{key.begin(), key.end()};
14051405

14061406
std::string type;
14071407
key >> type;
14081408

14091409
if (types.count(type) > 0) {
1410-
if (!m_batch->Erase(key_data)) {
1410+
if (!m_batch->Erase(Span{key_data})) {
14111411
cursor.reset(nullptr);
14121412
m_batch->TxnAbort();
14131413
return false; // erase failed

0 commit comments

Comments
 (0)