Skip to content

Commit

Permalink
Don't create empty transactions when reading corrupted wallet
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laanwj committed Dec 16, 2013
1 parent 93a7861 commit 16ec904
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
{
uint256 hash;
ssKey >> hash;
CWalletTx& wtx = pwallet->mapWallet[hash];
CWalletTx wtx;
ssValue >> wtx;
CValidationState state;
if (CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid())
wtx.BindWallet(pwallet);
else
{
pwallet->mapWallet.erase(hash);
return false;
}

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

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

0 comments on commit 16ec904

Please sign in to comment.