Skip to content

Commit

Permalink
keychain: ValidityPeriod Y2038 workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jan 15, 2021
1 parent 1956bd9 commit 660b0f4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ndnph/keychain/validity-period.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class ValidityPeriod
/** @brief Get a very long ValidityPeriod. */
static ValidityPeriod getMax()
{
return ValidityPeriod(540109800, 0xFFFFFFFF);
return ValidityPeriod(540109800, MaxTime::value);
}

ValidityPeriod() = default;

ValidityPeriod(time_t notBefore, time_t notAfter)
explicit ValidityPeriod(time_t notBefore, time_t notAfter)
: notBefore(notBefore)
, notAfter(notAfter)
{}
Expand Down Expand Up @@ -127,6 +127,9 @@ class ValidityPeriod

detail::UtcTimezone useUtc;
*v = mktime(&m);
if (sizeof(time_t) <= 4 && *v < 0 && (1900 + m.tm_year) >= 2038) {
*v = MaxTime::value;
}
return *v >= 0;
}

Expand All @@ -136,6 +139,11 @@ class ValidityPeriod

/** @brief NotAfter field in seconds since Unix epoch. */
time_t notAfter = 0;

private:
using MaxTime =
std::integral_constant<time_t,
sizeof(time_t) <= 4 ? std::numeric_limits<time_t>::max() : 253402300799>;
};

inline bool
Expand Down

0 comments on commit 660b0f4

Please sign in to comment.