Skip to content

Commit 1245c62

Browse files
author
MarcoFalke
committed
Merge bitcoin#24139: Avoid unsigned integer overflow in bitcoin-tx
faa75fa Avoid unsigned integer overflow in bitcoin-tx (MarcoFalke) Pull request description: While `npos` means "largest unsigned value" and adding `1` to it yields `0`, it may be clearer to just assign `0` to it and only increment otherwise. This also allows to remove a file-wide suppression for `unsigned-integer-overflow`. ACKs for top commit: hebasto: ACK faa75fa, I have reviewed the code and it looks OK, I agree it can be merged. theStack: Code-review ACK faa75fa Tree-SHA512: c24436641e5d801341c948b812c7f711d5dff70efdf04af00fd3221f4b81d93f25608dddaa36230ba81ca7ab0d18bdd957095d4561e22621e4d69017934f0a16
2 parents d4e92d8 + faa75fa commit 1245c62

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/bitcoin-tx.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,16 @@ static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strIn
434434
if (pos==0)
435435
throw std::runtime_error("TX output value not specified");
436436

437-
if (pos != std::string::npos) {
437+
if (pos == std::string::npos) {
438+
pos = 0;
439+
} else {
438440
// Extract and validate VALUE
439441
value = ExtractAndValidateValue(strInput.substr(0, pos));
442+
++pos;
440443
}
441444

442445
// extract and validate DATA
443-
std::string strData = strInput.substr(pos + 1, std::string::npos);
446+
const std::string strData{strInput.substr(pos, std::string::npos)};
444447

445448
if (!IsHex(strData))
446449
throw std::runtime_error("invalid TX output data");

test/sanitizer_suppressions/ubsan

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ shift-base:test/fuzz/crypto_diff_fuzz_chacha20.cpp
4545
# job.
4646
unsigned-integer-overflow:addrman.cpp
4747
unsigned-integer-overflow:arith_uint256.h
48-
unsigned-integer-overflow:bitcoin-tx.cpp
4948
unsigned-integer-overflow:common/bloom.cpp
5049
unsigned-integer-overflow:chain.cpp
5150
unsigned-integer-overflow:chain.h

0 commit comments

Comments
 (0)