From: Selva Nair Date: Sat, 30 Oct 2021 18:57:56 +0000 (-0400) Subject: Avoid memory leak in hmac_ctx_new (OpenSSL 3.0 only) X-Git-Tag: v2.6_beta1~395 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31e200f807033ac27566bf37a8d9d32820600a83;p=thirdparty%2Fopenvpn.git Avoid memory leak in hmac_ctx_new (OpenSSL 3.0 only) In OpenSSL 3.0, fetched algorithms must be freed (down referenced). In this case, though EVP_MAC_CTX_new() keeps a reference to 'hmac', it up-refs it. So we have to free it here before return. (Tested using an enable-asan build). Signed-off-by: Selva Nair Acked-by: Arne Schwabe Message-Id: <20211030185756.1831-1-selva.nair@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg23080.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index c43d18b9c..8e29a77b4 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -1097,6 +1097,9 @@ hmac_ctx_new(void) EVP_MAC *hmac = EVP_MAC_fetch(NULL, "HMAC", NULL); ctx->ctx = EVP_MAC_CTX_new(hmac); check_malloc_return(ctx->ctx); + + EVP_MAC_free(hmac); + return ctx; }