From: Ken Raeburn Date: Fri, 4 Jun 2004 22:44:30 +0000 (+0000) Subject: * asn1_encode.c (asn1_encode_generaltime): Use gmtime_r if available X-Git-Tag: krb5-1.4-beta1~358 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7de269508cdc32a64f236f1fbb7cd33608d5137c;p=krb5.git * asn1_encode.c (asn1_encode_generaltime): Use gmtime_r if available git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16414 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index b8b4d1025..f788a2f51 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,8 @@ +2004-06-04 Ken Raeburn + + * asn1_encode.c (asn1_encode_generaltime): Use gmtime_r if + available. + 2004-04-24 Ken Raeburn * asn1_decode.c (asn1_decode_generaltime): If the input string is diff --git a/src/lib/krb5/asn.1/asn1_encode.c b/src/lib/krb5/asn.1/asn1_encode.c index df3c4ec71..9d2912800 100644 --- a/src/lib/krb5/asn.1/asn1_encode.c +++ b/src/lib/krb5/asn.1/asn1_encode.c @@ -225,7 +225,7 @@ asn1_error_code asn1_encode_generaltime(asn1buf *buf, time_t val, unsigned int *retlen) { asn1_error_code retval; - struct tm *gtime; + struct tm *gtime, gtimebuf; char s[16], *sp; unsigned int length, sum=0; time_t gmt_time = val; @@ -241,10 +241,18 @@ asn1_error_code asn1_encode_generaltime(asn1buf *buf, time_t val, * Sanity check this just to be paranoid, as gmtime can return NULL, * and some bogus implementations might overrun on the sprintf. */ +#ifdef HAVE_GMTIME_R + if (gmtime_r(&gmt_time, >imebuf) == NULL) + return ASN1_BAD_GMTIME; +#else gtime = gmtime(&gmt_time); + if (gtime == NULL) + return ASN1_BAD_GMTIME; + memcpy(gtimebuf, gtime, sizeof(gtimebuf)); +#endif + gtime = >imebuf; - if (gtime == NULL || - gtime->tm_year > 8099 || gtime->tm_mon > 11 || + if (gtime->tm_year > 8099 || gtime->tm_mon > 11 || gtime->tm_mday > 31 || gtime->tm_hour > 23 || gtime->tm_min > 59 || gtime->tm_sec > 59) return ASN1_BAD_GMTIME;