From f7752adba5dd35fccd3f2144cfcf03538ebf275b Mon Sep 17 00:00:00 2001 From: fanquake Date: Fri, 9 Jul 2021 13:12:51 +0800 Subject: [PATCH] util: check MoneyRange() inside ParseMoney() --- src/test/util_tests.cpp | 2 +- src/util/moneystr.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index b953df580f8..4f9d10cf1d2 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1226,7 +1226,6 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney) BOOST_CHECK_EQUAL(ParseMoney("12345.6789").value(), (COIN/10000)*123456789); - BOOST_CHECK_EQUAL(ParseMoney("100000000.00").value(), COIN*100000000); BOOST_CHECK_EQUAL(ParseMoney("10000000.00").value(), COIN*10000000); BOOST_CHECK_EQUAL(ParseMoney("1000000.00").value(), COIN*1000000); BOOST_CHECK_EQUAL(ParseMoney("100000.00").value(), COIN*100000); @@ -1252,6 +1251,7 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney) BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001").value(), COIN/100000000); // Parsing amount that can not be represented should fail + BOOST_CHECK(!ParseMoney("100000000.00")); BOOST_CHECK(!ParseMoney("0.000000001")); // Parsing empty string should fail diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp index d72164f3bfa..d3f40296079 100644 --- a/src/util/moneystr.cpp +++ b/src/util/moneystr.cpp @@ -81,5 +81,9 @@ std::optional ParseMoney(const std::string& money_string) CAmount value = nWhole * COIN + nUnits; + if (!MoneyRange(value)) { + return std::nullopt; + } + return value; }