diff options
author | Nan Zhou <nanzhoumails@gmail.com> | 2021-11-30 09:23:18 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-12-11 08:42:00 +0300 |
commit | 1d8782e7a0ed98878bd82c24c7cf830bb8cdc46f (patch) | |
tree | b74013962c6b791d3e385bec2466fe02d3d0643b /redfish-core/lib/metric_report.hpp | |
parent | df5415fc03b458eedfcb07a6be262d1067a50aec (diff) | |
download | bmcweb-1d8782e7a0ed98878bd82c24c7cf830bb8cdc46f.tar.xz |
fix the year 2038 problem in getDateTime
The existing codes cast uint64_t into time_t which is int32_t in
most 32-bit systems. It results overflow if the timestamp is larger
than INT_MAX.
time_t will be 64 bits in future releases of glibc. See
https://sourceware.org/bugzilla/show_bug.cgi?id=28182.
This change workarounds the year 2038 problem via boost's ptime.
std::chrono doesn't help since it is still 32 bits.
Tested on QEMU.
Example output for certificate:
{
"Name": "HTTPS Certificate",
"Subject": null,
"ValidNotAfter": "2106-01-28T20:40:31Z",
"ValidNotBefore": "2106-02-06T18:28:16Z"
}
Previously, the format is like "1969-12-31T12:00:00+00:00". Note
that the ending "+00:00" is the time zone, not ms.
Tested the schema on QEMU. No new Redfish Service Validator errors.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8ef0bee3d724184d96253c23f3919447828d3f82
Diffstat (limited to 'redfish-core/lib/metric_report.hpp')
-rw-r--r-- | redfish-core/lib/metric_report.hpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp index c959495408..5ecab776b7 100644 --- a/redfish-core/lib/metric_report.hpp +++ b/redfish-core/lib/metric_report.hpp @@ -26,8 +26,7 @@ inline nlohmann::json toMetricValues(const Readings& readings) {"MetricId", id}, {"MetricProperty", metadata}, {"MetricValue", std::to_string(sensorValue)}, - {"Timestamp", - crow::utility::getDateTime(static_cast<time_t>(timestamp))}, + {"Timestamp", crow::utility::getDateTimeUint(timestamp)}, }); } @@ -53,8 +52,7 @@ inline bool fillReport(nlohmann::json& json, const std::string& id, } const auto& [timestamp, readings] = *timestampReadings; - json["Timestamp"] = - crow::utility::getDateTime(static_cast<time_t>(timestamp)); + json["Timestamp"] = crow::utility::getDateTimeUint(timestamp); json["MetricValues"] = toMetricValues(readings); return true; } |