Fix for d2i_ASN1_bytes and stop PKCS#7 routines crashing is signed message
[oweals/openssl.git] / crypto / asn1 / a_time.c
index c19b7b2cac58a1272b3a852f374c31a2f5ca533a..c1690a56949d4127d6ce9f4dba0cd208cdd9fce3 100644 (file)
 
 int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
        {
+#ifdef CHARSET_EBCDIC
+       /* KLUDGE! We convert to ascii before writing DER */
+       char tmp[24];
+       ASN1_STRING tmpstr;
+
+       if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
+           int len;
+
+           tmpstr = *(ASN1_STRING *)a;
+           len = tmpstr.length;
+           ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
+           tmpstr.data = tmp;
+           a = (ASN1_GENERALIZEDTIME *) &tmpstr;
+       }
+#endif
        if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
                                return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
                                     a->type ,V_ASN1_UNIVERSAL));
@@ -102,7 +117,7 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
 #else
        ts=gmtime(&t);
 #endif
-       if((ts->tm_year >= 1950) && (ts->tm_year < 2050))
+       if((ts->tm_year >= 50) && (ts->tm_year < 150))
                                        return ASN1_UTCTIME_set(s, t);
        return ASN1_GENERALIZEDTIME_set(s,t);
        }