Skip to content

Commit 19255f4

Browse files
committed
Backport compatibility changes for OpenSSL 4.0
This backports: - 266f85f - ff1bb13
1 parent 046ffa2 commit 19255f4

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
@@ -5,6 +5,9 @@ PHP NEWS
55
- Curl:
66
. Add support for brotli and zstd on Windows. (Shivam Mathur)
77

8+
- OpenSSL:
9+
. Fix compatibility issues with OpenSSL 4.0. (jordikroon, Remi)
10+
811
18 Dec 2025, PHP 8.2.30
912

1013
- Curl:

ext/openssl/openssl.c

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

471471
do {
472-
errors->top = (errors->top + 1) % ERR_NUM_ERRORS;
472+
errors->top = (errors->top + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
473473
if (errors->top == errors->bottom) {
474-
errors->bottom = (errors->bottom + 1) % ERR_NUM_ERRORS;
474+
errors->bottom = (errors->bottom + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
475475
}
476476
errors->buffer[errors->top] = error_code;
477477
} while ((error_code = ERR_get_error()));
@@ -685,7 +685,7 @@ static void php_openssl_add_assoc_name_entry(zval * val, char * key, X509_NAME *
685685

686686
static void php_openssl_add_assoc_asn1_string(zval * val, char * key, ASN1_STRING * str) /* {{{ */
687687
{
688-
add_assoc_stringl(val, key, (char *)str->data, str->length);
688+
add_assoc_stringl(val, key, (const char *)ASN1_STRING_get0_data(str), ASN1_STRING_length(str));
689689
}
690690
/* }}} */
691691

@@ -718,12 +718,12 @@ static time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
718718
}
719719

720720
if (timestr_len < 13 && timestr_len != 11) {
721-
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
721+
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
722722
return (time_t)-1;
723723
}
724724

725725
if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) {
726-
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
726+
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
727727
return (time_t)-1;
728728
}
729729

@@ -1982,8 +1982,8 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
19821982
}
19831983

19841984
extension_data = X509_EXTENSION_get_data(extension);
1985-
p = extension_data->data;
1986-
length = extension_data->length;
1985+
p = ASN1_STRING_get0_data(extension_data);
1986+
length = ASN1_STRING_length(extension_data);
19871987
if (method->it) {
19881988
names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL, &p, length,
19891989
ASN1_ITEM_ptr(method->it)));
@@ -6709,7 +6709,7 @@ PHP_FUNCTION(openssl_error_string)
67096709
RETURN_FALSE;
67106710
}
67116711

6712-
OPENSSL_G(errors)->bottom = (OPENSSL_G(errors)->bottom + 1) % ERR_NUM_ERRORS;
6712+
OPENSSL_G(errors)->bottom = (OPENSSL_G(errors)->bottom + 1) % PHP_OPENSSL_ERR_BUFFER_SIZE;
67136713
val = OPENSSL_G(errors)->buffer[OPENSSL_G(errors)->bottom];
67146714

67156715
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
@@ -497,12 +497,12 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
497497
}
498498
OPENSSL_free(cert_name);
499499
} else if (san->type == GEN_IPADD) {
500-
if (san->d.iPAddress->length == 4) {
500+
if (ASN1_STRING_length(san->d.iPAddress) == 4) {
501501
sprintf(ipbuffer, "%d.%d.%d.%d",
502-
san->d.iPAddress->data[0],
503-
san->d.iPAddress->data[1],
504-
san->d.iPAddress->data[2],
505-
san->d.iPAddress->data[3]
502+
ASN1_STRING_get0_data(san->d.iPAddress)[0],
503+
ASN1_STRING_get0_data(san->d.iPAddress)[1],
504+
ASN1_STRING_get0_data(san->d.iPAddress)[2],
505+
ASN1_STRING_get0_data(san->d.iPAddress)[3]
506506
);
507507
if (strcasecmp(subject_name, (const char*)ipbuffer) == 0) {
508508
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
@@ -511,9 +511,9 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
511511
}
512512
}
513513
#ifdef HAVE_IPV6_SAN
514-
else if (san->d.ip->length == 16 && subject_name_is_ipv6) {
514+
else if (ASN1_STRING_length(san->d.ip) == 16 && subject_name_is_ipv6) {
515515
ipbuffer[0] = 0;
516-
EXPAND_IPV6_ADDRESS(ipbuffer, san->d.iPAddress->data);
516+
EXPAND_IPV6_ADDRESS(ipbuffer, ASN1_STRING_get0_data(san->d.iPAddress));
517517
if (strcasecmp((const char*)subject_name_ipv6_expanded, (const char*)ipbuffer) == 0) {
518518
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
519519

0 commit comments

Comments
 (0)