Add support for some broken PKCS#8 formats.
[openssl.git] / crypto / asn1 / a_enum.c
index 32cfe5b599e75aa51960acd16782285d490ba3a8..ccf62e5a044011e95c6f04be609f6b2517d0ae11 100644 (file)
@@ -69,7 +69,7 @@ ASN1_ENUMERATED *ASN1_ENUMERATED_new(void)
 { return M_ASN1_ENUMERATED_new(); }
 
 void ASN1_ENUMERATED_free(ASN1_ENUMERATED *x)
-{ return M_ASN1_ENUMERATED_free(x); }
+{ M_ASN1_ENUMERATED_free(x); }
 
 int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
        {
@@ -177,7 +177,12 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
                goto err;
                }
        to=s;
-       if (*p & 0x80) /* a negative number */
+       if(!len) {
+               /* Strictly speaking this is an illegal ENUMERATED but we
+                * tolerate it.
+                */
+               ret->type=V_ASN1_ENUMERATED;
+       } else if (*p & 0x80) /* a negative number */
                {
                ret->type=V_ASN1_NEG_ENUMERATED;
                if ((*p == 0xff) && (len != 1)) {
@@ -214,7 +219,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
                p+=len;
        }
 
-       if (ret->data != NULL) Free((char *)ret->data);
+       if (ret->data != NULL) Free(ret->data);
        ret->data=s;
        ret->length=(int)len;
        if (a != NULL) (*a)=ret;
@@ -237,7 +242,7 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
        if (a->length < (sizeof(long)+1))
                {
                if (a->data != NULL)
-                       Free((char *)a->data);
+                       Free(a->data);
                if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
                        memset((char *)a->data,0,sizeof(long)+1);
                }