From: Benjamin Kaduk Date: Thu, 12 Oct 2017 17:12:10 +0000 (-0500) Subject: Fix memory leak in DH_get_nid() X-Git-Tag: OpenSSL_1_1_1-pre1~554 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8abeefeccc4cfbfba9b5ebfc7604fe257a97317a;p=oweals%2Fopenssl.git Fix memory leak in DH_get_nid() If q is non-NULL but p is indeed a safe prime, a modified copy of p could be leaked. Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/4525) --- diff --git a/crypto/dh/dh_rfc7919.c b/crypto/dh/dh_rfc7919.c index d01ba6fdf3..a54b468e55 100644 --- a/crypto/dh/dh_rfc7919.c +++ b/crypto/dh/dh_rfc7919.c @@ -66,10 +66,9 @@ int DH_get_nid(const DH *dh) BIGNUM *q = BN_dup(dh->p); /* Check q = p * 2 + 1 we already know q is odd, so just shift right */ - if (q == NULL || !BN_rshift1(q, q) || !BN_cmp(dh->q, q)) { - BN_free(q); - return NID_undef; - } + if (q == NULL || !BN_rshift1(q, q) || !BN_cmp(dh->q, q)) + nid = NID_undef; + BN_free(q); } return nid; }