Fix memory leak in s2i_ASN_INTEGER and return an error
authorDr. Stephen Henson <steve@openssl.org>
Wed, 13 Nov 2002 00:40:51 +0000 (00:40 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 13 Nov 2002 00:40:51 +0000 (00:40 +0000)
if any invalid characters are present.

crypto/x509v3/v3_utl.c

index 283e943e4624d96311749410b3cc4322e09f6c1f..1f0db94776d1daa455f3127751f212e07a513370 100644 (file)
@@ -156,11 +156,11 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
        ASN1_INTEGER *aint;
        int isneg, ishex;
        int ret;
-       bn = BN_new();
        if (!value) {
                X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
                return 0;
        }
+       bn = BN_new();
        if (value[0] == '-') {
                value++;
                isneg = 1;
@@ -174,7 +174,8 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
        if (ishex) ret = BN_hex2bn(&bn, value);
        else ret = BN_dec2bn(&bn, value);
 
-       if (!ret) {
+       if (!ret || value[ret]) {
+               BN_free(bn);
                X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
                return 0;
        }