Tolerate critical AKID in CRLs.
[oweals/openssl.git] / crypto / asn1 / a_object.c
index 6e4ae3b0730a89790482ca1744e3f0fcc8102fd1..ca73a281f5579b224e1dfab15b7161bcc525c94a 100644 (file)
@@ -62,6 +62,7 @@
 #include <openssl/buffer.h>
 #include <openssl/asn1.h>
 #include <openssl/objects.h>
+#include <openssl/bn.h>
 
 int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
        {
@@ -138,7 +139,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
                                ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
                                goto err;
                                }
-                       if (!use_bn && l > (ULONG_MAX / 10L))
+                       if (!use_bn && l >= ((ULONG_MAX - 80) / 10L))
                                {
                                use_bn = 1;
                                if (!bl)
@@ -247,7 +248,11 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
                i2t_ASN1_OBJECT(p,i + 1,a);
                }
        if (i <= 0)
-               return BIO_write(bp, "<INVALID>", 9);
+                {
+                i = BIO_write(bp, "<INVALID>", 9);
+                i += BIO_dump(bp, (const char *)a->data, a->length);
+                return i;
+                }
        BIO_write(bp,p,i);
        if (p != buf)
                OPENSSL_free(p);
@@ -289,6 +294,17 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
        const unsigned char *p;
        unsigned char *data;
        int i;
+       /* Sanity check OID encoding: can't have leading 0x80 in
+        * subidentifiers, see: X.690 8.19.2
+        */
+       for (i = 0, p = *pp; i < len; i++, p++)
+               {
+               if (*p == 0x80 && (!i || !(p[-1] & 0x80)))
+                       {
+                       ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING);
+                       return NULL;
+                       }
+               }
 
        /* only the ASN1_OBJECTs from the 'table' will have values
         * for ->sn or ->ln */