Skip to content

Commit faa75fa

Browse files
author
MarcoFalke
committed
Avoid unsigned integer overflow in bitcoin-tx
1 parent e3de7cb commit faa75fa

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
@@ -433,13 +433,16 @@ static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strIn
433433
if (pos==0)
434434
throw std::runtime_error("TX output value not specified");
435435

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

441444
// extract and validate DATA
442-
std::string strData = strInput.substr(pos + 1, std::string::npos);
445+
const std::string strData{strInput.substr(pos, std::string::npos)};
443446

444447
if (!IsHex(strData))
445448
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)