Skip to content

Commit 16ec904

Browse files
committed
Don't create empty transactions when reading corrupted wallet
The current transaction loading code is not exception safe. An exception during deserialization causes an empty transaction to be left behind in the wallet. Fix this by building the transaction separately and adding it only to the wallet at the end. Fixes #3333.
1 parent 93a7861 commit 16ec904

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/walletdb.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
357357
{
358358
uint256 hash;
359359
ssKey >> hash;
360-
CWalletTx& wtx = pwallet->mapWallet[hash];
360+
CWalletTx wtx;
361361
ssValue >> wtx;
362362
CValidationState state;
363363
if (CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid())
364364
wtx.BindWallet(pwallet);
365365
else
366-
{
367-
pwallet->mapWallet.erase(hash);
368366
return false;
369-
}
370367

371368
// Undo serialize changes in 31600
372369
if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
@@ -391,6 +388,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
391388
if (wtx.nOrderPos == -1)
392389
wss.fAnyUnordered = true;
393390

391+
pwallet->mapWallet[hash] = wtx;
394392
//// debug print
395393
//LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
396394
//LogPrintf(" %12"PRId64" %s %s %s\n",

0 commit comments

Comments
 (0)