From 9f0327e6520098068389b78a7e87a0d9c3627631 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Sun, 8 Nov 2009 18:55:52 +0100 Subject: [PATCH] define TIME_32_BITS_SIGNED_MAX in utils.h --- src/libstrongswan/asn1/asn1.c | 8 +++----- src/libstrongswan/plugins/pgp/pgp_cert.c | 4 ++-- src/libstrongswan/utils.h | 5 +++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c index 418b47338..0b6859690 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 3a7179fd3..4807e1741 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 c506761c0..f54aa16de 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. */