From: Juergen Perlinger Date: Mon, 4 Apr 2011 16:37:14 +0000 (+0200) Subject: bug1875: timegm() from libntp blows up with 64bit time_t on Windows X-Git-Tag: NTP_4_2_7P147~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e789b1131d0925a54fb414712c95d64d9d825dd6;p=thirdparty%2Fntp.git bug1875: timegm() from libntp blows up with 64bit time_t on Windows bk: 4d99f3bangeMLZW0lXR9eQv6Jyji5A --- diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index 44ad2d1d8..f2b5c1117 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -1903,7 +1903,7 @@ asn2ntp ( ) { char *v; /* pointer to ASN1_TIME string */ - struct tm tm; /* used to convert to NTP time */ + struct calendar jd; /* used to convert to NTP time */ /* * Extract time string YYMMDDHHMMSSZ from ASN1 time structure. @@ -1913,18 +1913,19 @@ asn2ntp ( * 100. Dontcha love ASN.1? Better than MIL-188. */ v = (char *)asn1time->data; - tm.tm_year = (v[0] - '0') * 10 + v[1] - '0'; - if (tm.tm_year < 50) - tm.tm_year += 100; - tm.tm_mon = (v[2] - '0') * 10 + v[3] - '0' - 1; - tm.tm_mday = (v[4] - '0') * 10 + v[5] - '0'; - tm.tm_hour = (v[6] - '0') * 10 + v[7] - '0'; - tm.tm_min = (v[8] - '0') * 10 + v[9] - '0'; - tm.tm_sec = (v[10] - '0') * 10 + v[11] - '0'; - tm.tm_wday = 0; - tm.tm_yday = 0; - tm.tm_isdst = 0; - return ((u_long)timegm(&tm) + JAN_1970); + jd.year = (v[0] - '0') * 10 + v[1] - '0'; + if (jd.year < 50) + jd.year += 100; + jd.year += 1900; /* should we do century unfolding here? */ + jd.month = (v[2] - '0') * 10 + v[3] - '0'; + jd.monthday = (v[4] - '0') * 10 + v[5] - '0'; + jd.hour = (v[6] - '0') * 10 + v[7] - '0'; + jd.minute = (v[8] - '0') * 10 + v[9] - '0'; + jd.second = (v[10] - '0') * 10 + v[11] - '0'; + jd.yearday = 0; + jd.weekday = 0; + + return caltontp(&jd); }