Skip to content

Commit 5bd7e3b

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Backport compatibility changes for OpenSSL 4.0
2 parents 1f50b63 + ccb9ec6 commit 5bd7e3b

4 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
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed tracing JIT crash when a VM interrupt is handled during an observed
77
user function call. (Levi Morrison)
88

9+
- OpenSSL:
10+
. Fix compatibility issues with OpenSSL 4.0. (jordikroon, Remi)
11+
912
- Standard:
1013
. Fixed bug GH-21689 (version_compare() incorrectly handles versions ending
1114
with a dot). (timwolla)

ext/openssl/openssl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,9 @@ void php_openssl_store_errors(void)
492492
errors = OPENSSL_G(errors);
493493

494494
do {
495-
errors->top = (errors->top + 1) % ERR_NUM_ERRORS;
495+
errors->top = (errors->top + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
496496
if (errors->top == errors->bottom) {
497-
errors->bottom = (errors->bottom + 1) % ERR_NUM_ERRORS;
497+
errors->bottom = (errors->bottom + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
498498
}
499499
errors->buffer[errors->top] = error_code;
500500
} while ((error_code = ERR_get_error()));
@@ -739,7 +739,7 @@ static void php_openssl_add_assoc_name_entry(zval * val, char * key, X509_NAME *
739739

740740
static void php_openssl_add_assoc_asn1_string(zval * val, char * key, ASN1_STRING * str) /* {{{ */
741741
{
742-
add_assoc_stringl(val, key, (char *)str->data, str->length);
742+
add_assoc_stringl(val, key, (const char *)ASN1_STRING_get0_data(str), ASN1_STRING_length(str));
743743
}
744744
/* }}} */
745745

@@ -772,12 +772,12 @@ static time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
772772
}
773773

774774
if (timestr_len < 13) {
775-
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
775+
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
776776
return (time_t)-1;
777777
}
778778

779779
if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) {
780-
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
780+
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
781781
return (time_t)-1;
782782
}
783783

@@ -2040,8 +2040,8 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
20402040
}
20412041

20422042
extension_data = X509_EXTENSION_get_data(extension);
2043-
p = extension_data->data;
2044-
length = extension_data->length;
2043+
p = ASN1_STRING_get0_data(extension_data);
2044+
length = ASN1_STRING_length(extension_data);
20452045
if (method->it) {
20462046
names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL, &p, length,
20472047
ASN1_ITEM_ptr(method->it)));
@@ -7226,7 +7226,7 @@ PHP_FUNCTION(openssl_error_string)
72267226
RETURN_FALSE;
72277227
}
72287228

7229-
OPENSSL_G(errors)->bottom = (OPENSSL_G(errors)->bottom + 1) % ERR_NUM_ERRORS;
7229+
OPENSSL_G(errors)->bottom = (OPENSSL_G(errors)->bottom + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
72307230
val = OPENSSL_G(errors)->buffer[OPENSSL_G(errors)->bottom];
72317231

72327232
if (val) {

ext/openssl/php_openssl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ extern zend_module_entry openssl_module_entry;
4444
#endif
4545
#endif
4646

47+
#define PHP_OPENSSL_ERR_BUFFER_SIZE 16
48+
4749
#define OPENSSL_RAW_DATA 1
4850
#define OPENSSL_ZERO_PADDING 2
4951
#define OPENSSL_DONT_ZERO_PAD_KEY 4
@@ -73,7 +75,7 @@ extern zend_module_entry openssl_module_entry;
7375
#endif
7476

7577
struct php_openssl_errors {
76-
int buffer[ERR_NUM_ERRORS];
78+
int buffer[PHP_OPENSSL_ERR_BUFFER_SIZE];
7779
int top;
7880
int bottom;
7981
};

ext/openssl/xp_ssl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,12 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
496496
}
497497
OPENSSL_free(cert_name);
498498
} else if (san->type == GEN_IPADD) {
499-
if (san->d.iPAddress->length == 4) {
499+
if (ASN1_STRING_length(san->d.iPAddress) == 4) {
500500
snprintf(ipbuffer, sizeof(ipbuffer), "%d.%d.%d.%d",
501-
san->d.iPAddress->data[0],
502-
san->d.iPAddress->data[1],
503-
san->d.iPAddress->data[2],
504-
san->d.iPAddress->data[3]
501+
ASN1_STRING_get0_data(san->d.iPAddress)[0],
502+
ASN1_STRING_get0_data(san->d.iPAddress)[1],
503+
ASN1_STRING_get0_data(san->d.iPAddress)[2],
504+
ASN1_STRING_get0_data(san->d.iPAddress)[3]
505505
);
506506
if (strcasecmp(subject_name, (const char*)ipbuffer) == 0) {
507507
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
@@ -510,9 +510,9 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
510510
}
511511
}
512512
#ifdef HAVE_IPV6_SAN
513-
else if (san->d.ip->length == 16 && subject_name_is_ipv6) {
513+
else if (ASN1_STRING_length(san->d.ip) == 16 && subject_name_is_ipv6) {
514514
ipbuffer[0] = 0;
515-
EXPAND_IPV6_ADDRESS(ipbuffer, san->d.iPAddress->data);
515+
EXPAND_IPV6_ADDRESS(ipbuffer, ASN1_STRING_get0_data(san->d.iPAddress));
516516
if (strcasecmp((const char*)subject_name_ipv6_expanded, (const char*)ipbuffer) == 0) {
517517
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
518518

0 commit comments

Comments
 (0)