Skip to content

Commit fa07f84

Browse files
author
MarcoFalke
committed
Fix signed integer overflow in prioritisetransaction RPC
1 parent fa52cf8 commit fa07f84

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/txmempool.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <reverse_iterator.h>
1717
#include <util/check.h>
1818
#include <util/moneystr.h>
19+
#include <util/overflow.h>
1920
#include <util/system.h>
2021
#include <util/time.h>
2122
#include <validationinterface.h>
@@ -93,9 +94,9 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
9394

9495
void CTxMemPoolEntry::UpdateModifiedFee(CAmount fee_diff)
9596
{
96-
nModFeesWithDescendants += fee_diff;
97-
nModFeesWithAncestors += fee_diff;
98-
m_modified_fee += fee_diff;
97+
nModFeesWithDescendants = SaturatingAdd(nModFeesWithDescendants, fee_diff);
98+
nModFeesWithAncestors = SaturatingAdd(nModFeesWithAncestors, fee_diff);
99+
m_modified_fee = SaturatingAdd(m_modified_fee, fee_diff);
99100
}
100101

101102
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
@@ -437,7 +438,7 @@ void CTxMemPoolEntry::UpdateDescendantState(int64_t modifySize, CAmount modifyFe
437438
{
438439
nSizeWithDescendants += modifySize;
439440
assert(int64_t(nSizeWithDescendants) > 0);
440-
nModFeesWithDescendants += modifyFee;
441+
nModFeesWithDescendants = SaturatingAdd(nModFeesWithDescendants, modifyFee);
441442
nCountWithDescendants += modifyCount;
442443
assert(int64_t(nCountWithDescendants) > 0);
443444
}
@@ -446,7 +447,7 @@ void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee,
446447
{
447448
nSizeWithAncestors += modifySize;
448449
assert(int64_t(nSizeWithAncestors) > 0);
449-
nModFeesWithAncestors += modifyFee;
450+
nModFeesWithAncestors = SaturatingAdd(nModFeesWithAncestors, modifyFee);
450451
nCountWithAncestors += modifyCount;
451452
assert(int64_t(nCountWithAncestors) > 0);
452453
nSigOpCostWithAncestors += modifySigOps;
@@ -921,7 +922,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
921922
{
922923
LOCK(cs);
923924
CAmount &delta = mapDeltas[hash];
924-
delta += nFeeDelta;
925+
delta = SaturatingAdd(delta, nFeeDelta);
925926
txiter it = mapTx.find(hash);
926927
if (it != mapTx.end()) {
927928
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });

test/sanitizer_suppressions/ubsan

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -fsanitize=undefined suppressions
22
# =================================
3-
# This would be `signed-integer-overflow:CTxMemPool::PrioritiseTransaction`,
3+
# The suppressions would be `sanitize-type:ClassName::MethodName`,
44
# however due to a bug in clang the symbolizer is disabled and thus no symbol
55
# names can be used.
66
# See https://github.com/google/sanitizers/issues/1364
7-
signed-integer-overflow:txmempool.cpp
7+
88
# https://github.com/bitcoin/bitcoin/pull/21798#issuecomment-829180719
99
signed-integer-overflow:policy/feerate.cpp
1010

0 commit comments

Comments
 (0)