From 9b34b10e79cd3eed057fcdbab35cb0989656a055 Mon Sep 17 00:00:00 2001 From: icy17 <1061499390@qq.com> Date: Fri, 29 Sep 2023 16:50:21 +0800 Subject: [PATCH 1/2] add check against NULL before calling EVP_DigestInit_ex to avoid NULL deref --- ext/openssl/openssl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 33f51bfa4de9..6035e78f8749 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -7342,6 +7342,12 @@ PHP_FUNCTION(openssl_digest) sigbuf = zend_string_alloc(siglen, 0); md_ctx = EVP_MD_CTX_create(); + + // add check against NULL + if(!md_ctx){ + RETURN_FALSE; + } + if (EVP_DigestInit(md_ctx, mdtype) && EVP_DigestUpdate(md_ctx, (unsigned char *)data, data_len) && EVP_DigestFinal (md_ctx, (unsigned char *)ZSTR_VAL(sigbuf), &siglen)) { From 10d652e3033c98ba852c261cd5c654b290cf2fe5 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 29 Sep 2023 18:47:14 +0100 Subject: [PATCH 2/2] Formatting Co-authored-by: Jakub Zelenka --- ext/openssl/openssl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 6035e78f8749..d2ee66d4e1ac 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -7344,7 +7344,7 @@ PHP_FUNCTION(openssl_digest) md_ctx = EVP_MD_CTX_create(); // add check against NULL - if(!md_ctx){ + if (md_ctx == NULL) { RETURN_FALSE; }