Skip to content

Commit 8888461

Browse files
author
MarcoFalke
committed
util: Fail to parse empty string in ParseMoney
1 parent fab30b6 commit 8888461

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/test/util_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,12 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
11991199
BOOST_CHECK(ParseMoney("0.00000001", ret));
12001200
BOOST_CHECK_EQUAL(ret, COIN/100000000);
12011201

1202+
// Parsing amount that can not be represented in ret should fail
1203+
BOOST_CHECK(!ParseMoney("0.000000001", ret));
1204+
1205+
// Parsing empty string should fail
1206+
BOOST_CHECK(!ParseMoney("", ret));
1207+
12021208
// Attempted 63 bit overflow should fail
12031209
BOOST_CHECK(!ParseMoney("92233720368.54775808", ret));
12041210

src/util/moneystr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ bool ParseMoney(const std::string& str, CAmount& nRet)
3737
return false;
3838
}
3939

40+
if (str.empty()) {
41+
return false;
42+
}
43+
4044
std::string strWhole;
4145
int64_t nUnits = 0;
4246
const char* p = str.c_str();

0 commit comments

Comments
 (0)