Skip to content

Commit 137c80d

Browse files
tests: Add tests for decoding/parsing of base32, base64 and money strings containing NUL characters
1 parent a6fc26d commit 137c80d

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/test/base32_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ BOOST_AUTO_TEST_CASE(base32_testvectors)
2020
std::string strDec = DecodeBase32(vstrOut[i]);
2121
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
2222
}
23+
24+
// Decoding strings with embedded NUL characters should fail
25+
bool failure;
26+
(void)DecodeBase32(std::string("invalid", 7), &failure);
27+
BOOST_CHECK_EQUAL(failure, true);
28+
(void)DecodeBase32(std::string("AWSX3VPP", 8), &failure);
29+
BOOST_CHECK_EQUAL(failure, false);
30+
(void)DecodeBase32(std::string("AWSX3VPP\0invalid", 16), &failure);
31+
BOOST_CHECK_EQUAL(failure, true);
32+
(void)DecodeBase32(std::string("AWSX3VPPinvalid", 15), &failure);
33+
BOOST_CHECK_EQUAL(failure, true);
2334
}
2435

2536
BOOST_AUTO_TEST_SUITE_END()

src/test/base64_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ BOOST_AUTO_TEST_CASE(base64_testvectors)
2020
std::string strDec = DecodeBase64(strEnc);
2121
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
2222
}
23+
24+
// Decoding strings with embedded NUL characters should fail
25+
bool failure;
26+
(void)DecodeBase64(std::string("invalid", 7), &failure);
27+
BOOST_CHECK_EQUAL(failure, true);
28+
(void)DecodeBase64(std::string("nQB/pZw=", 8), &failure);
29+
BOOST_CHECK_EQUAL(failure, false);
30+
(void)DecodeBase64(std::string("nQB/pZw=\0invalid", 16), &failure);
31+
BOOST_CHECK_EQUAL(failure, true);
32+
(void)DecodeBase64(std::string("nQB/pZw=invalid", 15), &failure);
33+
BOOST_CHECK_EQUAL(failure, true);
2334
}
2435

2536
BOOST_AUTO_TEST_SUITE_END()

src/test/util_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,11 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
10691069

10701070
// Parsing negative amounts must fail
10711071
BOOST_CHECK(!ParseMoney("-1", ret));
1072+
1073+
// Parsing strings with embedded NUL characters should fail
1074+
BOOST_CHECK(!ParseMoney(std::string("\0-1", 3), ret));
1075+
BOOST_CHECK(!ParseMoney(std::string("\01", 2), ret));
1076+
BOOST_CHECK(!ParseMoney(std::string("1\0", 2), ret));
10721077
}
10731078

10741079
BOOST_AUTO_TEST_CASE(util_IsHex)

0 commit comments

Comments
 (0)