boost::posix_time
in ParseISO8601DateTime
has many issues:
- It parses random strings that are clearly invalid and returns a time value for them, see [1] below.
- None of the separators
-
, or:
, orT
, orZ
are validated. - It may crash when running under a hardened C++ library, see #28917.
- It has been unmaintained for years, so reporting or fixing any issues will most likely be useless.
- It pulls in a third-party dependency, when the functionality is already included in vanilla C++20.
Fix all issues by replacing it with a simple helper function written in C++20.
Fixes #28917.
[1] The following patch passes on current master:
0diff --git a/src/wallet/test/rpc_util_tests.cpp b/src/wallet/test/rpc_util_tests.cpp
1index 32f6f5ab46..c1c94c7116 100644
2--- a/src/wallet/test/rpc_util_tests.cpp
3+++ b/src/wallet/test/rpc_util_tests.cpp
4@@ -12,6 +12,14 @@ BOOST_AUTO_TEST_SUITE(wallet_util_tests)
5
6 BOOST_AUTO_TEST_CASE(util_ParseISO8601DateTime)
7 {
8+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("964296"), 242118028800);
9+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("244622"), 15023836800);
10+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("+INfINITy"), 9223372036854);
11+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("7000802 01"), 158734166400);
12+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("7469-2 +INfINITy"), 9223372036854);
13+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("maXimum-datE-time"), 253402300799);
14+ BOOST_CHECK_EQUAL(ParseISO8601DateTime("577737 114maXimum-datE-time"), 253402300799);
15+
16 BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0);
17 BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0);
18 BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:01Z"), 946684801);