aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-02-11 17:26:40 +0100
committerMarcoFalke <falke.marco@gmail.com>2022-02-11 17:21:44 +0100
commitfa6065661a86656a29e89ed1a3529cb7103f5394 (patch)
tree2e45c008ce1bc6a519aa29f9e3417afed052cea0
parentb79c40b057ec39045d0036d978b3c01a5cf9f712 (diff)
refactor: Avoid unsigned integer overflow in core_write
-rw-r--r--src/core_write.cpp2
-rw-r--r--test/sanitizer_suppressions/ubsan1
2 files changed, 1 insertions, 2 deletions
diff --git a/src/core_write.cpp b/src/core_write.cpp
index 5ea62cf3ed..c4b6b8d27e 100644
--- a/src/core_write.cpp
+++ b/src/core_write.cpp
@@ -65,7 +65,7 @@ std::string FormatScript(const CScript& script)
ret += strprintf("0x%x ", HexStr(std::vector<uint8_t>(it2, script.end())));
break;
}
- return ret.substr(0, ret.size() - 1);
+ return ret.substr(0, ret.empty() ? ret.npos : ret.size() - 1);
}
const std::map<unsigned char, std::string> mapSigHashTypes = {
diff --git a/test/sanitizer_suppressions/ubsan b/test/sanitizer_suppressions/ubsan
index 2084e02b8a..bdaee5d191 100644
--- a/test/sanitizer_suppressions/ubsan
+++ b/test/sanitizer_suppressions/ubsan
@@ -47,7 +47,6 @@ unsigned-integer-overflow:arith_uint256.h
unsigned-integer-overflow:common/bloom.cpp
unsigned-integer-overflow:coins.cpp
unsigned-integer-overflow:compressor.cpp
-unsigned-integer-overflow:core_write.cpp
unsigned-integer-overflow:crypto/
unsigned-integer-overflow:hash.cpp
unsigned-integer-overflow:policy/fees.cpp