Since there's no continuation, the ; can go as well :-)
[oweals/openssl.git] / crypto / asn1 / a_int.c
index c18376be48a09cdd16679cb971a927d9938c1aa4..edb243c0217eeb625d3ea738b1cca4bf636e7c66 100644 (file)
@@ -360,7 +360,7 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a)
        if (i == V_ASN1_NEG_INTEGER)
                neg=1;
        else if (i != V_ASN1_INTEGER)
-               return(0);
+               return -1;
        
        if (a->length > sizeof(long))
                {
@@ -368,7 +368,7 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a)
                return(0xffffffffL);
                }
        if (a->data == NULL)
-               return(0);
+               return 0;
 
        for (i=0; i<a->length; i++)
                {
@@ -397,8 +397,23 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
        else ret->type=V_ASN1_INTEGER;
        j=BN_num_bits(bn);
        len=((j == 0)?0:((j/8)+1));
-       ret->data=(unsigned char *)OPENSSL_malloc(len+4);
+       if (ret->length < len+4)
+               {
+               unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
+               if (!new_data)
+                       {
+                       ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
+                       goto err;
+                       }
+               ret->data=new_data;
+               }
        ret->length=BN_bn2bin(bn,ret->data);
+       /* Correct zero case */
+       if(!ret->length)
+               {
+               ret->data[0] = 0;
+               ret->length = 1;
+               }
        return(ret);
 err:
        if (ret != ai) M_ASN1_INTEGER_free(ret);