Skip to content

Commit 9f2f390

Browse files
thepastaclawclaude
andcommitted
fix: resolve signed integer overflow UB in CoinJoin priority and timeout
CalculateAmountPriority in common.h could overflow when assigning a negated int64_t division result to an int return type with extreme CAmount values. Add a MoneyRange guard to return 0 for out-of-range inputs, as CoinJoin amounts are always within valid money range. IsTimeOutOfBounds in coinjoin.cpp could overflow on signed subtraction when current_time and nTime are extreme values. Add a guard rejecting negative timestamps (which are always invalid) so the original subtraction logic is safe for all remaining non-negative inputs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1d212a1 commit 9f2f390

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/coinjoin/coinjoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ bool CCoinJoinQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const
5757

5858
bool CCoinJoinQueue::IsTimeOutOfBounds(int64_t current_time) const
5959
{
60+
if (current_time < 0 || nTime < 0) return true;
6061
return current_time - nTime > COINJOIN_QUEUE_TIMEOUT ||
6162
nTime - current_time > COINJOIN_QUEUE_TIMEOUT;
6263
}

src/coinjoin/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ constexpr int CalculateAmountPriority(CAmount nInputAmount)
127127
}
128128

129129
//nondenom return largest first
130+
if (nInputAmount < 0 || nInputAmount > MAX_MONEY) return 0;
130131
return -1 * (nInputAmount / COIN);
131132
}
132133

0 commit comments

Comments
 (0)