Fix a typo in a_enum.c.
[openssl.git] / crypto / asn1 / a_enum.c
index 9239ecc439a0ee477e7c60ae8e98d32816660e22..56ee787a23e0cdbe8fcca1c0e338e3ef3aeb5ecc 100644 (file)
  * for comments on encoding see a_int.c
  */
 
+ASN1_ENUMERATED *ASN1_ENUMERATED_new(void)
+{ return M_ASN1_ENUMERATED_new(); }
+
+void ASN1_ENUMERATED_free(ASN1_ENUMERATED *x)
+{ M_ASN1_ENUMERATED_free(x); }
+
 int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
        {
        int pad=0,ret,r,i,t;
@@ -142,7 +148,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
 
        if ((a == NULL) || ((*a) == NULL))
                {
-               if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL);
+               if ((ret=M_ASN1_ENUMERATED_new()) == NULL) return(NULL);
                ret->type=V_ASN1_ENUMERATED;
                }
        else
@@ -171,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)) {
@@ -217,7 +228,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
 err:
        ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
        if ((ret != NULL) && ((a == NULL) || (*a != ret)))
-               ASN1_ENUMERATED_free(ret);
+               M_ASN1_ENUMERATED_free(ret);
        return(NULL);
        }
 
@@ -295,7 +306,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
        int len,j;
 
        if (ai == NULL)
-               ret=ASN1_ENUMERATED_new();
+               ret=M_ASN1_ENUMERATED_new();
        else
                ret=ai;
        if (ret == NULL)
@@ -311,7 +322,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
        ret->length=BN_bn2bin(bn,ret->data);
        return(ret);
 err:
-       if (ret != ai) ASN1_ENUMERATED_free(ret);
+       if (ret != ai) M_ASN1_ENUMERATED_free(ret);
        return(NULL);
        }