From: Matt Caswell Date: Mon, 9 Feb 2015 11:38:41 +0000 (+0000) Subject: Fix a failure to NULL a pointer freed on error. X-Git-Tag: OpenSSL_1_1_0-pre1~1609 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9e442d485008046933cdc7da65080f436a4af089;p=oweals%2Fopenssl.git Fix a failure to NULL a pointer freed on error. Inspired by BoringSSL commit 517073cd4b by Eric Roman CVE-2015-0209 Reviewed-by: Emilia Käsper --- diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index 292437409f..1088e8916e 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -1033,8 +1033,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len) ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); goto err; } - if (a) - *a = ret; } else ret = *a; @@ -1102,10 +1100,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len) ret->enc_flag |= EC_PKEY_NO_PUBKEY; } + if (a) + *a = ret; ok = 1; err: if (!ok) { - if (ret) + if (ret && (a == NULL || *a != ret)) EC_KEY_free(ret); ret = NULL; }