Skip to content

Commit 4660fc8

Browse files
committed
wallet: Check last block and conflict height are valid in MarkConflicted
MarkConflicted calculates conflict confirmations incorrectly when both the last block processed height and the conflicting height are negative (i.e. uninitialized). If either are negative, we should not be marking conflicts and should exit early.
1 parent c9f2882 commit 4660fc8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,11 +1339,14 @@ void CWallet::MarkConflicted(const uint256& hashBlock, int conflicting_height, c
13391339
{
13401340
LOCK(cs_wallet);
13411341

1342-
int conflictconfirms = (m_last_block_processed_height - conflicting_height + 1) * -1;
13431342
// If number of conflict confirms cannot be determined, this means
13441343
// that the block is still unknown or not yet part of the main chain,
13451344
// for example when loading the wallet during a reindex. Do nothing in that
13461345
// case.
1346+
if (m_last_block_processed_height < 0 || conflicting_height < 0) {
1347+
return;
1348+
}
1349+
int conflictconfirms = (m_last_block_processed_height - conflicting_height + 1) * -1;
13471350
if (conflictconfirms >= 0)
13481351
return;
13491352

0 commit comments

Comments
 (0)