From: Andreas Steffen Date: Sun, 8 Nov 2009 17:55:52 +0000 (+0100) Subject: define TIME_32_BITS_SIGNED_MAX in utils.h X-Git-Tag: 4.3.6~259 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f0327e6520098068389b78a7e87a0d9c3627631;p=thirdparty%2Fstrongswan.git define TIME_32_BITS_SIGNED_MAX in utils.h --- diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c index 418b47338d..0b68596903 100644 --- a/src/libstrongswan/asn1/asn1.c +++ b/src/libstrongswan/asn1/asn1.c @@ -231,8 +231,6 @@ int asn1_unwrap(chunk_t *blob, chunk_t *inner) return type; } -#define TIME_MAX 0x7fffffff - static const int days[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; static const int tm_leap_1970 = 477; @@ -306,7 +304,7 @@ time_t asn1_to_time(const chunk_t *utctime, asn1_t type) /* prevent large 32 bit integer overflows */ if (sizeof(time_t) == 4 && tm_year > 2038) { - return TIME_MAX; + return TIME_32_BIT_SIGNED_MAX; } /* representation of months as 0..11*/ @@ -334,8 +332,8 @@ time_t asn1_to_time(const chunk_t *utctime, asn1_t type) tm_days = 365 * (tm_year - 1970) + days[tm_mon] + tm_day + tm_leap; tm_secs = 60 * (60 * (24 * tm_days + tm_hour) + tm_min) + tm_sec - tz_offset; - /* has a 32 bit overflow occurred? */ - return (tm_secs < 0) ? TIME_MAX : tm_secs; + /* has a 32 bit signed integer overflow occurred? */ + return (tm_secs < 0) ? TIME_32_BIT_SIGNED_MAX : tm_secs; } /** diff --git a/src/libstrongswan/plugins/pgp/pgp_cert.c b/src/libstrongswan/plugins/pgp/pgp_cert.c index 3a7179fd30..4807e17414 100644 --- a/src/libstrongswan/plugins/pgp/pgp_cert.c +++ b/src/libstrongswan/plugins/pgp/pgp_cert.c @@ -163,8 +163,8 @@ static bool get_validity(private_pgp_cert_t *this, time_t *when, } else { - /* year 2038 */ - until = 2147483647; + /* Jan 19 03:14:07 UTC 2038 */ + until = TIME_32_BIT_SIGNED_MAX; } if (not_after) { diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index c506761c07..f54aa16de4 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -131,6 +131,11 @@ */ #define UNDEFINED_TIME 0 +/** + * Maximum time since epoch causing wrap-around on Jan 19 03:14:07 UTC 2038 + */ +#define TIME_32_BIT_SIGNED_MAX 0x7fffffff + /** * General purpose boolean type. */