From fa6065661a86656a29e89ed1a3529cb7103f5394 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 11 Feb 2022 17:26:40 +0100 Subject: [PATCH] refactor: Avoid unsigned integer overflow in core_write --- src/core_write.cpp | 2 +- test/sanitizer_suppressions/ubsan | 1 - 2 files changed, 1 insertion(+), 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(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 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