diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 949f5d76245e..164cf0862861 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -7379,6 +7379,12 @@ PHP_FUNCTION(openssl_digest) sigbuf = zend_string_alloc(siglen, 0); md_ctx = EVP_MD_CTX_create(); + + // add check against NULL + if (md_ctx == NULL) { + 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)) {