Skip to content

Commit 36c0554

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix error check on X509_set_subject_name() Fix crash when ASN1_STRING_to_UTF8() fails
2 parents fc55723 + a8b7665 commit 36c0554

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

ext/openssl/openssl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,10 @@ PHP_FUNCTION(openssl_csr_sign)
18181818
PHP_OPENSSL_ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial);
18191819
}
18201820

1821-
X509_set_subject_name(new_cert, X509_REQ_get_subject_name(csr));
1821+
if (!X509_set_subject_name(new_cert, X509_REQ_get_subject_name(csr))) {
1822+
php_openssl_store_errors();
1823+
goto cleanup;
1824+
}
18221825

18231826
if (cert == NULL) {
18241827
cert = new_cert;

ext/openssl/xp_ssl.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@
128128
#define GET_VER_OPT_LONG(_name, _num) \
129129
if (GET_VER_OPT(_name)) _num = zval_get_long(val)
130130

131-
/* Used for peer verification in windows */
132-
#define PHP_X509_NAME_ENTRY_TO_UTF8(ne, i, out) \
133-
ASN1_STRING_to_UTF8(&out, X509_NAME_ENTRY_get_data(X509_NAME_get_entry(ne, i)))
134-
135131
#ifdef HAVE_IPV6
136132
/* Used for IPv6 Address peer verification */
137133
#define EXPAND_IPV6_ADDRESS(_str, _bytes) \
@@ -474,7 +470,10 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
474470
GENERAL_NAME *san = sk_GENERAL_NAME_value(alt_names, i);
475471

476472
if (san->type == GEN_DNS) {
477-
ASN1_STRING_to_UTF8(&cert_name, san->d.dNSName);
473+
if (ASN1_STRING_to_UTF8(&cert_name, san->d.dNSName) < 0) {
474+
/* TODO: warn ? */
475+
continue;
476+
}
478477
if ((size_t)ASN1_STRING_length(san->d.dNSName) != strlen((const char*)cert_name)) {
479478
OPENSSL_free(cert_name);
480479
/* prevent null-byte poisoning*/

0 commit comments

Comments
 (0)