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
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 2f88a77..8e1a6f4 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -1171,12 +1171,11 @@
}
// LastStateChangeTime is epoch time, in milliseconds
// https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19
- time_t lastResetTimeStamp =
- static_cast<time_t>(*lastResetTimePtr / 1000);
+ uint64_t lastResetTimeStamp = *lastResetTimePtr / 1000;
// Convert to ISO 8601 standard
aResp->res.jsonValue["LastResetTime"] =
- crow::utility::getDateTime(lastResetTimeStamp);
+ crow::utility::getDateTimeUint(lastResetTimeStamp);
},
"xyz.openbmc_project.State.Chassis",
"/xyz/openbmc_project/state/chassis0",