Commit 42c392c5781 for php.net

commit 42c392c5781fd527bb1720c4ed6a4254c28b0ad8
Author: Nora Dossche <7771979+ndossche@users.noreply.github.com>
Date:   Thu Jun 25 08:33:17 2026 +0200

    openssl: Use proper error propagation when X509_dup() fails in openssl_x509_read() (#21953)

    Otherwise x509 field is NULL and can cause a NULL deref which is UB (and
    causes a SEGV).

diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 2c5a93c8992..cd16db03b8d 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -2518,9 +2518,20 @@ PHP_FUNCTION(openssl_x509_read)
 		RETURN_FALSE;
 	}

+	X509 *obj_x509;
+	if (cert_obj) {
+		obj_x509 = X509_dup(cert);
+		if (!obj_x509) {
+			php_error_docref(NULL, E_WARNING, "X.509 Certificate could not be duplicated");
+			RETURN_FALSE;
+		}
+	} else {
+		obj_x509 = cert;
+	}
+
 	object_init_ex(return_value, php_openssl_certificate_ce);
 	x509_cert_obj = Z_OPENSSL_CERTIFICATE_P(return_value);
-	x509_cert_obj->x509 = cert_obj ? X509_dup(cert) : cert;
+	x509_cert_obj->x509 = obj_x509;
 }
 /* }}} */