Skip to content

Commit cf7b509

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Backport compatibility changes for OpenSSL 4.0
2 parents e384585 + 5bd7e3b commit cf7b509

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PHP NEWS
99
. Fixed tracing JIT crash when a VM interrupt is handled during an observed
1010
user function call. (Levi Morrison)
1111

12+
- OpenSSL:
13+
. Fix compatibility issues with OpenSSL 4.0. (jordikroon, Remi)
14+
1215
- Standard:
1316
. Fixed bug GH-21689 (version_compare() incorrectly handles versions ending
1417
with a dot). (timwolla)

ext/openssl/openssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ void php_openssl_store_errors(void)
218218
errors = OPENSSL_G(errors);
219219

220220
do {
221-
errors->top = (errors->top + 1) % ERR_NUM_ERRORS;
221+
errors->top = (errors->top + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
222222
if (errors->top == errors->bottom) {
223-
errors->bottom = (errors->bottom + 1) % ERR_NUM_ERRORS;
223+
errors->bottom = (errors->bottom + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
224224
}
225225
errors->buffer[errors->top] = error_code;
226226
} while ((error_code = ERR_get_error()));
@@ -4046,7 +4046,7 @@ PHP_FUNCTION(openssl_error_string)
40464046
RETURN_FALSE;
40474047
}
40484048

4049-
OPENSSL_G(errors)->bottom = (OPENSSL_G(errors)->bottom + 1) % ERR_NUM_ERRORS;
4049+
OPENSSL_G(errors)->bottom = (OPENSSL_G(errors)->bottom + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
40504050
val = OPENSSL_G(errors)->buffer[OPENSSL_G(errors)->bottom];
40514051

40524052
if (val) {

ext/openssl/openssl_backend_common.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, X509_NAME * name,
110110

111111
void php_openssl_add_assoc_asn1_string(zval * val, char * key, ASN1_STRING * str)
112112
{
113-
add_assoc_stringl(val, key, (char *)str->data, str->length);
113+
add_assoc_stringl(val, key, (const char *)ASN1_STRING_get0_data(str), ASN1_STRING_length(str));
114114
}
115115

116116
time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
@@ -142,12 +142,12 @@ time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
142142
}
143143

144144
if (timestr_len < 13) {
145-
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
145+
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
146146
return (time_t)-1;
147147
}
148148

149149
if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) {
150-
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
150+
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
151151
return (time_t)-1;
152152
}
153153

@@ -630,8 +630,8 @@ int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
630630
}
631631

632632
extension_data = X509_EXTENSION_get_data(extension);
633-
p = extension_data->data;
634-
length = extension_data->length;
633+
p = ASN1_STRING_get0_data(extension_data);
634+
length = ASN1_STRING_length(extension_data);
635635
if (method->it) {
636636
names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL, &p, length,
637637
ASN1_ITEM_ptr(method->it)));

ext/openssl/php_openssl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extern zend_module_entry openssl_module_entry;
3636
#define PHP_OPENSSL_API_VERSION 0x30200
3737
#endif
3838

39+
#define PHP_OPENSSL_ERR_BUFFER_SIZE 16
40+
3941
#define OPENSSL_RAW_DATA 1
4042
#define OPENSSL_ZERO_PADDING 2
4143
#define OPENSSL_DONT_ZERO_PAD_KEY 4
@@ -65,7 +67,7 @@ extern zend_module_entry openssl_module_entry;
6567
#endif
6668

6769
struct php_openssl_errors {
68-
int buffer[ERR_NUM_ERRORS];
70+
int buffer[PHP_OPENSSL_ERR_BUFFER_SIZE];
6971
int top;
7072
int bottom;
7173
};

ext/openssl/xp_ssl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,12 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
494494
}
495495
OPENSSL_free(cert_name);
496496
} else if (san->type == GEN_IPADD) {
497-
if (san->d.iPAddress->length == 4) {
497+
if (ASN1_STRING_length(san->d.iPAddress) == 4) {
498498
snprintf(ipbuffer, sizeof(ipbuffer), "%d.%d.%d.%d",
499-
san->d.iPAddress->data[0],
500-
san->d.iPAddress->data[1],
501-
san->d.iPAddress->data[2],
502-
san->d.iPAddress->data[3]
499+
ASN1_STRING_get0_data(san->d.iPAddress)[0],
500+
ASN1_STRING_get0_data(san->d.iPAddress)[1],
501+
ASN1_STRING_get0_data(san->d.iPAddress)[2],
502+
ASN1_STRING_get0_data(san->d.iPAddress)[3]
503503
);
504504
if (strcasecmp(subject_name, (const char*)ipbuffer) == 0) {
505505
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
@@ -508,9 +508,9 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
508508
}
509509
}
510510
#ifdef HAVE_IPV6_SAN
511-
else if (san->d.ip->length == 16 && subject_name_is_ipv6) {
511+
else if (ASN1_STRING_length(san->d.ip) == 16 && subject_name_is_ipv6) {
512512
ipbuffer[0] = 0;
513-
EXPAND_IPV6_ADDRESS(ipbuffer, san->d.iPAddress->data);
513+
EXPAND_IPV6_ADDRESS(ipbuffer, ASN1_STRING_get0_data(san->d.iPAddress));
514514
if (strcasecmp((const char*)subject_name_ipv6_expanded, (const char*)ipbuffer) == 0) {
515515
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
516516

0 commit comments

Comments
 (0)