aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2009-03-27 08:54:10 +0000
committerAndreas Steffen <andreas.steffen@strongswan.org>2009-03-27 08:54:10 +0000
commit5021380d35d063a1ee54c495a08455c2d2abcc39 (patch)
tree50e95800880b11e0ec9f58fcda7bd49ccb8ec79e /src/libstrongswan
parent6527da58ae61c18ab1d488bfe9e5c4b8d937c2db (diff)
downloadstrongswan-5021380d35d063a1ee54c495a08455c2d2abcc39.tar.bz2
strongswan-5021380d35d063a1ee54c495a08455c2d2abcc39.tar.xz
fixed ASN.1 to time_t conversion on 32-bit system for dates after Jan 19 03:14:07 UTC 2038
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/asn1/asn1.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c
index dacf12c01..6dd90b7e5 100644
--- a/src/libstrongswan/asn1/asn1.c
+++ b/src/libstrongswan/asn1/asn1.c
@@ -264,13 +264,15 @@ u_int asn1_length(chunk_t *blob)
return len;
}
+#define TIME_MAX 0x7fffffff
+
/**
* Converts ASN.1 UTCTIME or GENERALIZEDTIME into calender time
*/
time_t asn1_to_time(const chunk_t *utctime, asn1_t type)
{
struct tm t;
- time_t tz_offset;
+ time_t tc, tz_offset;
u_char *eot = NULL;
if ((eot = memchr(utctime->ptr, 'Z', utctime->len)) != NULL)
@@ -296,12 +298,13 @@ time_t asn1_to_time(const chunk_t *utctime, asn1_t type)
return 0; /* error in time format */
}
+ /* parse ASN.1 time string */
{
- const char* format = (type == ASN1_UTCTIME)? "%2d%2d%2d%2d%2d":
- "%4d%2d%2d%2d%2d";
+ const char* format = (type == ASN1_UTCTIME)? "%2d%2d%2d%2d%2d":
+ "%4d%2d%2d%2d%2d";
- sscanf(utctime->ptr, format, &t.tm_year, &t.tm_mon, &t.tm_mday,
- &t.tm_hour, &t.tm_min);
+ sscanf(utctime->ptr, format, &t.tm_year, &t.tm_mon, &t.tm_mday,
+ &t.tm_hour, &t.tm_min);
}
/* is there a seconds field? */
@@ -334,9 +337,11 @@ time_t asn1_to_time(const chunk_t *utctime, asn1_t type)
/* set daylight saving time to off */
t.tm_isdst = 0;
- /* compensate timezone */
-
- return mktime(&t) - timezone - tz_offset;
+ /* convert to time_t */
+ tc = mktime(&t);
+
+ /* if no conversion overflow occurred, compensate timezone */
+ return (tc == -1) ? TIME_MAX : tc - timezone - tz_offset;
}
/**