[php-src] PHP-8.5: Fix GH-20920: do not use OPENSSL_strndup() for peer CN matching

From: Date: Tue, 24 Nov 2026 12:10:01 +0000
Subject: [php-src] PHP-8.5: Fix GH-20920: do not use OPENSSL_strndup() for peer CN matching
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144101@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Date: 2026-11-24T12:39:07+01:00 Commit: https://github.com/php/php-src/commit/686bf38f9388971e27b2c9bc1fb14495c46bf892 Raw diff: https://github.com/php/php-src/commit/686bf38f9388971e27b2c9bc1fb14495c46bf892.diff Fix GH-20920: do not use OPENSSL_strndup() for peer CN matching OPENSSL_strndup() is not available in LibreSSL so the build fails at link time since it started to be used in 4f2f4892061. Use estrndup() instead. The embedded NUL check keeps working because the copy is compared against the ASN.1 string length. Changed paths: M ext/openssl/xp_ssl.c Diff: diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 8e3463907df8..c36e9e9adc27 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -569,15 +569,11 @@ static bool php_openssl_matches_common_name(X509 *peer, const char *subject_name name_asn1 = X509_NAME_ENTRY_get_data(name_entry); cert_name_len = ASN1_STRING_get_length(name_asn1); - cert_name = (unsigned char *) OPENSSL_strndup((const char *) ASN1_STRING_get0_data(name_asn1), cert_name_len); - if (cert_name == NULL) { - php_error_docref(NULL, E_WARNING, "Unable to locate peer certificate CN"); - return false; - } + cert_name = (unsigned char *) estrndup((const char *) ASN1_STRING_get0_data(name_asn1), cert_name_len); if ((size_t)cert_name_len != strlen((const char *)cert_name)) { php_error_docref(NULL, E_WARNING, "Peer certificate CN=`%.*s' is malformed", cert_name_len, (const char *)cert_name); - OPENSSL_free(cert_name); + efree(cert_name); return false; } else if (php_openssl_matches_wildcard_name(subject_name, (const char *)cert_name)) { is_match = 1; @@ -585,11 +581,11 @@ static bool php_openssl_matches_common_name(X509 *peer, const char *subject_name php_error_docref(NULL, E_WARNING, "Peer certificate CN=%.*s' did not match expected CN=%s'", cert_name_len, (const char *)cert_name, subject_name); - OPENSSL_free(cert_name); + efree(cert_name); return false; } - OPENSSL_free(cert_name); + efree(cert_name); return is_match; }

« previous php.cvs (#144101) next »