use ERR_peek_last_error() instead of ERR_peek_error() to ignore
[openssl.git] / crypto / asn1 / a_gentm.c
index d71c190c776e8beff3d35ba984db493b71979a91..cd09f68b38f61baff588199f848b4088ab84d77c 100644 (file)
@@ -61,6 +61,7 @@
 #include <stdio.h>
 #include <time.h>
 #include "cryptlib.h"
+#include "o_time.h"
 #include <openssl/asn1.h>
 
 #if 0
@@ -145,6 +146,19 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
 
                if ((n < min[i]) || (n > max[i])) goto err;
                }
+       /* Optional fractional seconds: decimal point followed by one
+        * or more digits.
+        */
+       if (a[o] == '.')
+               {
+               if (++o > l) goto err;
+               i = o;
+               while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
+                       o++;
+               /* Must have at least one digit after decimal point */
+               if (i == o) goto err;
+               }
+
        if (a[o] == 'Z')
                o++;
        else if ((a[o] == '+') || (a[o] == '-'))
@@ -180,6 +194,7 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
                        {
                        ASN1_STRING_set((ASN1_STRING *)s,
                                (unsigned char *)str,t.length);
+                       s->type=V_ASN1_GENERALIZEDTIME;
                        }
                return(1);
                }
@@ -192,21 +207,17 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
        {
        char *p;
        struct tm *ts;
-#if defined(THREADS) && !defined(WIN32)
        struct tm data;
-#endif
 
        if (s == NULL)
                s=M_ASN1_GENERALIZEDTIME_new();
        if (s == NULL)
                return(NULL);
 
-#if defined(THREADS) && !defined(WIN32)
-       gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */
-       ts=&data;
-#else
-       ts=gmtime(&t);
-#endif
+       ts=OPENSSL_gmtime(&t, &data);
+       if (ts == NULL)
+               return(NULL);
+
        p=(char *)s->data;
        if ((p == NULL) || (s->length < 16))
                {