Fixes to various ASN1_INTEGER routines for negative case.
[openssl.git] / crypto / asn1 / a_int.c
index b0fc97ea273a3e0debf1504f71a0524b87c676f1..496704b9a52636235f14ae1ddd15feb7af6b289c 100644 (file)
@@ -399,6 +399,12 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
        len=((j == 0)?0:((j/8)+1));
        ret->data=(unsigned char *)OPENSSL_malloc(len+4);
        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);