Commit 62afc7a2fa9 for php.net

commit 62afc7a2fa93f2d8e8dc2c98fa25bfc56c7e0508
Author: Niels Dossche <7771979+ndossche@users.noreply.github.com>
Date:   Thu Jan 22 22:09:40 2026 +0100

    Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails

    The X509_NAME_oneline() function can return NULL, which will cause a
    crash when the string length is computed via add_assoc_string().

    Closes GH-21010.

diff --git a/NEWS b/NEWS
index ecc0aaee316..e229b4aaec3 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,8 @@ PHP                                                                        NEWS
   . Fix memory leaks when sk_X509_new_null() fails. (ndossche)
   . Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails.
     (ndossche)
+  . Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails.
+    (ndossche)

 - Phar:
   . Fixed bug GH-20882 (buildFromIterator breaks with missing base directory).
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 415974f2fa7..12383ac8c2c 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -2134,6 +2134,11 @@ PHP_FUNCTION(openssl_x509_parse)

 	subject_name = X509_get_subject_name(cert);
 	cert_name = X509_NAME_oneline(subject_name, NULL, 0);
+	if (cert_name == NULL) {
+		php_openssl_store_errors();
+		goto err;
+	}
+
 	add_assoc_string(return_value, "name", cert_name);
 	OPENSSL_free(cert_name);