* asn1_encode.c (asn1_encode_generaltime): Use gmtime_r if available
authorKen Raeburn <raeburn@mit.edu>
Fri, 4 Jun 2004 22:44:30 +0000 (22:44 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 4 Jun 2004 22:44:30 +0000 (22:44 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16414 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/ChangeLog
src/lib/krb5/asn.1/asn1_encode.c

index b8b4d1025e1a913f2616dfd12b243240dca70e35..f788a2f51b97213078755b0d0c394acfbc3dd620 100644 (file)
@@ -1,3 +1,8 @@
+2004-06-04  Ken Raeburn  <raeburn@mit.edu>
+
+       * asn1_encode.c (asn1_encode_generaltime): Use gmtime_r if
+       available.
+
 2004-04-24  Ken Raeburn  <raeburn@mit.edu>
 
        * asn1_decode.c (asn1_decode_generaltime): If the input string is
index df3c4ec713fbbe8f03b2ef101cdf17e52e0f770e..9d2912800bbf83689eaeccec572b7a5bef9f318e 100644 (file)
@@ -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, &gtimebuf) == NULL)
+         return ASN1_BAD_GMTIME;
+#else
       gtime = gmtime(&gmt_time);
+      if (gtime == NULL)
+         return ASN1_BAD_GMTIME;
+      memcpy(gtimebuf, gtime, sizeof(gtimebuf));
+#endif
+      gtime = &gtimebuf;
 
-      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;