diff options
| author | Francis Dupont <fdupont@isc.org> | 2022-08-31 15:36:21 +0200 |
|---|---|---|
| committer | Francis Dupont <fdupont@isc.org> | 2022-09-23 16:01:36 +0200 |
| commit | 0b3efadffaa69cd823de6d95f5263e3b67e41778 (patch) | |
| tree | d8f09655e9c86f3c5e09e91ea613ff2d7a576829 /src/lib/pgsql/pgsql_exchange.cc | |
| parent | 6428e0219faa0258c20c3d0a1d43dcb9af21e9ab (diff) | |
[#2532] Fixed 2038 vs postgreSQL issue
Diffstat (limited to 'src/lib/pgsql/pgsql_exchange.cc')
| -rw-r--r-- | src/lib/pgsql/pgsql_exchange.cc | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/pgsql/pgsql_exchange.cc b/src/lib/pgsql/pgsql_exchange.cc index a646c46fb1..d203714108 100644 --- a/src/lib/pgsql/pgsql_exchange.cc +++ b/src/lib/pgsql/pgsql_exchange.cc @@ -239,11 +239,17 @@ PsqlBindArray::addTimestamp(const boost::posix_time::ptime& timestamp) { // Sadly boost::posix_time::to_time_t() was not added until 1.58, // so do it ourselves. ptime epoch(boost::gregorian::date(1970, 1, 1)); + if (timestamp < epoch) { + isc_throw(isc::BadValue, "Time value is before the epoch"); + } + ptime max_db_time = boost::posix_time::from_time_t(DatabaseConnection::MAX_DB_TIME); time_duration::sec_type since_epoch = (timestamp - epoch).total_seconds(); time_t input_time(since_epoch); - - if (input_time > DatabaseConnection::MAX_DB_TIME) { - isc_throw(isc::BadValue, "Time value is too large: " << input_time); + if (timestamp > max_db_time) { + isc_throw(isc::BadValue, "Time value is too large: " << + (input_time < 0 ? + static_cast<int64_t>(static_cast<uint32_t>(input_time)) : + input_time)); } // Converts to timestamp to local date/time string. |
