diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-10-08 15:51:55 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-10-11 09:17:28 +0200 |
commit | fa43e7c2d9dc5e2df70acd2019bdd24023c1d333 (patch) | |
tree | e6ca1f9c45b419fa04392566b88c38fddac384e0 /src | |
parent | fa053c0019bc8b2174c485f4885f894f2b5de472 (diff) | |
download | bitcoin-fa43e7c2d9dc5e2df70acd2019bdd24023c1d333.tar.xz |
bitcoin-tx: Avoid treating overflow as OP_0
Diffstat (limited to 'src')
-rw-r--r-- | src/core_read.cpp | 6 | ||||
-rw-r--r-- | src/test/script_parse_tests.cpp | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp index 3bbecbf52b..2149b428d2 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -66,16 +66,16 @@ CScript ParseScript(const std::string& s) (w.front() == '-' && w.size() > 1 && std::all_of(w.begin() + 1, w.end(), ::IsDigit))) { // Number - int64_t n = LocaleIndependentAtoi<int64_t>(w); + const auto num{ToIntegral<int64_t>(w)}; // limit the range of numbers ParseScript accepts in decimal // since numbers outside -0xFFFFFFFF...0xFFFFFFFF are illegal in scripts - if (n > int64_t{0xffffffff} || n < -1 * int64_t{0xffffffff}) { + if (!num.has_value() || num > int64_t{0xffffffff} || num < -1 * int64_t{0xffffffff}) { throw std::runtime_error("script parse error: decimal numeric value only allowed in the " "range -0xFFFFFFFF...0xFFFFFFFF"); } - result << n; + result << num.value(); } else if (w.substr(0, 2) == "0x" && w.size() > 2 && IsHex(std::string(w.begin() + 2, w.end()))) { // Raw hex data, inserted NOT pushed onto stack: std::vector<unsigned char> raw = ParseHex(std::string(w.begin() + 2, w.end())); diff --git a/src/test/script_parse_tests.cpp b/src/test/script_parse_tests.cpp index 5b8b6a725f..004c1a9a84 100644 --- a/src/test/script_parse_tests.cpp +++ b/src/test/script_parse_tests.cpp @@ -38,7 +38,6 @@ BOOST_AUTO_TEST_CASE(parse_script) {"'17'", "023137"}, {"ELSE", "67"}, {"NOP10", "b9"}, - {"11111111111111111111", "00"}, }; std::string all_in; std::string all_out; @@ -49,6 +48,7 @@ BOOST_AUTO_TEST_CASE(parse_script) } BOOST_CHECK_EQUAL(HexStr(ParseScript(all_in)), all_out); + BOOST_CHECK_EXCEPTION(ParseScript("11111111111111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF")); BOOST_CHECK_EXCEPTION(ParseScript("11111111111"), std::runtime_error, HasReason("script parse error: decimal numeric value only allowed in the range -0xFFFFFFFF...0xFFFFFFFF")); BOOST_CHECK_EXCEPTION(ParseScript("OP_CHECKSIGADD"), std::runtime_error, HasReason("script parse error: unknown opcode")); } |