From bbbbaa0d9ac9ae9c9b8109503aa30213eed543b9 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 31 Jan 2022 14:28:35 +0100 Subject: [PATCH] Fix unsigned integer overflows in interpreter --- src/script/interpreter.cpp | 4 ++-- test/sanitizer_suppressions/ubsan | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index dcdddb88e96ef..a35306b693557 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -51,8 +51,8 @@ bool CastToBool(const valtype& vch) * Script is a stack machine (like Forth) that evaluates a predicate * returning a bool indicating valid or not. There are no loops. */ -#define stacktop(i) (stack.at(stack.size()+(i))) -#define altstacktop(i) (altstack.at(altstack.size()+(i))) +#define stacktop(i) (stack.at(size_t(int64_t(stack.size()) + int64_t{i}))) +#define altstacktop(i) (altstack.at(size_t(int64_t(altstack.size()) + int64_t{i}))) static inline void popstack(std::vector& stack) { if (stack.empty()) diff --git a/test/sanitizer_suppressions/ubsan b/test/sanitizer_suppressions/ubsan index 94bd14e6c3f98..6e636b56b8e77 100644 --- a/test/sanitizer_suppressions/ubsan +++ b/test/sanitizer_suppressions/ubsan @@ -55,7 +55,6 @@ unsigned-integer-overflow:MurmurHash3 unsigned-integer-overflow:CBlockPolicyEstimator::processBlockTx unsigned-integer-overflow:TxConfirmStats::EstimateMedianVal unsigned-integer-overflow:prevector.h -unsigned-integer-overflow:EvalScript unsigned-integer-overflow:InsecureRandomContext::rand64 unsigned-integer-overflow:InsecureRandomContext::SplitMix64 unsigned-integer-overflow:bitset_detail::PopCount