[php-src] master: Merge branch 'PHP-8.6'
| From: | ndossche | Date: | Mon, 26 Oct 2026 17:44:18 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142751@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-10-26T18:44:06+01:00
Commit: https://github.com/php/php-src/commit/746a684eae06aae68bb1e2d590980683aa8a60ba
Raw diff: https://github.com/php/php-src/commit/746a684eae06aae68bb1e2d590980683aa8a60ba.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix GH-24438: Preserve indirect types in JIT side traces
Fix GH-17733: System entropy does not take into account function order, resulting in wrong
functions possibly called in different configurations
ext/openssl: Fix build with OpenSSL 4.1 (#24686)
Changed paths:
A ext/opcache/tests/gh17733.phpt
A ext/opcache/tests/jit/gh24438.phpt
A ext/openssl/tests/openssl_spki_export_challenge_binary.phpt
M Zend/zend_API.c
M Zend/zend_system_id.c
M ext/opcache/jit/zend_jit_trace.c
M ext/opcache/zend_file_cache.c
M ext/openssl/openssl.c
M ext/openssl/openssl_backend_common.c
M ext/openssl/php_openssl_backend.h
M ext/openssl/tests/session_resumption_get_cb_num_tickets_positive.phpt
M ext/openssl/tests/session_unserialize_repeat.phpt
M ext/openssl/xp_ssl.c
Diff:
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 28439b6e3015..6b1da965ef76 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -34,7 +34,6 @@
#include "zend_enum.h"
#include "zend_object_handlers.h"
#include "zend_observer.h"
-#include "zend_system_id.h"
#include <stdarg.h>
@@ -3229,7 +3228,6 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const
zend
}
zend_flf_handlers[zend_flf_count] = flf_info->handler;
zend_flf_functions[zend_flf_count] = (zend_function *)reg_function;
- zend_add_system_entropy("frameless", ZSTR_VAL(reg_function->function_name),
&flf_info->num_args, sizeof(flf_info->num_args));
zend_flf_count++;
flf_info++;
}
diff --git a/Zend/zend_system_id.c b/Zend/zend_system_id.c
index 3e5077279b7e..cdba4ea6fcaf 100644
--- a/Zend/zend_system_id.c
+++ b/Zend/zend_system_id.c
@@ -87,6 +87,21 @@ void zend_finalize_system_id(void)
}
}
+ /* Cached scripts can refer to offsets of internal functions.
+ * Effects of disable_functions and frameless functions must be taken into account.
+ * Therefore, embed the function names in-order.
+ * Updating third party extensions may change function signatures, arginfo, offsets, ...
+ * Therefore, also embed the loaded modules and their versions. */
+ ZEND_HASH_MAP_FOREACH_STR_KEY(CG(function_table), zend_string *name) {
+ PHP_MD5Update(&context, ZSTR_VAL(name), ZSTR_LEN(name) + 1);
+ } ZEND_HASH_FOREACH_END();
+ ZEND_HASH_MAP_FOREACH_PTR(&module_registry, zend_module_entry *mod) {
+ PHP_MD5Update(&context, mod->name, strlen(mod->name) + 1);
+ if (EXPECTED(mod->version != NO_VERSION_YET)) {
+ PHP_MD5Update(&context, mod->version, strlen(mod->version) + 1);
+ }
+ } ZEND_HASH_FOREACH_END();
+
PHP_MD5Final(digest, &context);
zend_bin2hex(zend_system_id, digest, sizeof digest);
finalized = 1;
diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c
index 93c0630b9286..e974dd5b1430 100644
--- a/ext/opcache/jit/zend_jit_trace.c
+++ b/ext/opcache/jit/zend_jit_trace.c
@@ -1774,7 +1774,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer,
uin
if (i < op_array->last_var) {
ssa_var_info[i].type = MAY_BE_UNDEF | MAY_BE_RC1 | MAY_BE_RCN | MAY_BE_REF | MAY_BE_ANY |
MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
} else {
- ssa_var_info[i].type = MAY_BE_RC1 | MAY_BE_RCN | MAY_BE_REF | MAY_BE_ANY |
MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
+ ssa_var_info[i].type = MAY_BE_RC1 | MAY_BE_RCN | MAY_BE_REF | MAY_BE_INDIRECT | MAY_BE_ANY |
MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
}
}
if (i < parent_vars_count) {
diff --git a/ext/opcache/tests/gh17733.phpt b/ext/opcache/tests/gh17733.phpt
new file mode 100644
index 000000000000..89f604597bd6
--- /dev/null
+++ b/ext/opcache/tests/gh17733.phpt
@@ -0,0 +1,110 @@
+--TEST--
+GH-17733 (System entropy does not take into account function order, resulting in wrong functions
possibly called in different configurations)
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+$cache = __DIR__ . '/' . 'gh17733';
+$script = $cache . '/' . 'call.php';
+mkdir($cache);
+
+function write_script(string $script, int $version): void {
+ file_put_contents($script, <<<PHP
+ <?php
+ echo "v$version\n";
+ try {
+ var_dump(str_repeat("ab", 3));
+ } catch (\Throwable \$e) {
+ echo \$e::class, ": ", \$e->getMessage(), "\n";
+ }
+ PHP);
+}
+
+function run(string $cache, string $script, string $disable_functions): void {
+ $ext = ini_get('extension_dir');
+ $opcache = PHP_OS_FAMILY === 'Windows' ? 'php_opcache.dll' :
'opcache.so';
+ $cmd = [PHP_BINARY, '-n', '-d', 'extension_dir="' . $ext .
'"'];
+ if (file_exists($ext . '/' . $opcache)) {
+ array_push($cmd, '-d', 'zend_extension=opcache');
+ }
+ array_push($cmd,
+ '-d', 'opcache.enable_cli=1',
+ '-d', 'opcache.file_cache="' . $cache . '"',
+ '-d', 'opcache.file_cache_only=1',
+ '-d', 'opcache.file_update_protection=0',
+ '-d', 'opcache.validate_timestamps=0', // Important to tell apart
versions
+ '-d', 'disable_functions=' . $disable_functions,
+ $script,
+ );
+ $proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 =>
['redirect', 1]], $pipes);
+ echo stream_get_contents($pipes[1]);
+ proc_close($proc);
+}
+
+function system_ids(string $cache): int {
+ $pattern = PHP_OS_FAMILY === 'Windows' ? '/*/*' : '/*';
+ return count(glob($cache . $pattern, GLOB_ONLYDIR));
+}
+
+write_script($script, 1);
+run($cache, $script, '');
+var_dump(system_ids($cache));
+
+write_script($script, 2);
+echo "--- Same environment reuses the cache ---\n";
+run($cache, $script, '');
+var_dump(system_ids($cache));
+
+echo "--- Shifted function table ---\n";
+run($cache, $script, 'zend_version');
+var_dump(system_ids($cache));
+
+echo "--- Disabled function ---\n";
+run($cache, $script, 'str_repeat');
+var_dump(system_ids($cache));
+
+write_script($script, 3);
+echo "--- Each environment reuses its own cache ---\n";
+run($cache, $script, 'zend_version');
+run($cache, $script, 'str_repeat');
+run($cache, $script, '');
+var_dump(system_ids($cache));
+?>
+--CLEAN--
+<?php
+$cache = __DIR__ . '/' . 'gh17733';
+if (is_dir($cache)) {
+ $it = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator($cache, FilesystemIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::CHILD_FIRST
+ );
+ foreach ($it as $file) {
+ $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname());
+ }
+ rmdir($cache);
+}
+?>
+--EXPECT--
+v1
+string(6) "ababab"
+int(1)
+--- Same environment reuses the cache ---
+v1
+string(6) "ababab"
+int(1)
+--- Shifted function table ---
+v2
+string(6) "ababab"
+int(2)
+--- Disabled function ---
+v2
+Error: Call to undefined function str_repeat()
+int(3)
+--- Each environment reuses its own cache ---
+v2
+string(6) "ababab"
+v2
+Error: Call to undefined function str_repeat()
+v1
+string(6) "ababab"
+int(3)
diff --git a/ext/opcache/tests/jit/gh24438.phpt b/ext/opcache/tests/jit/gh24438.phpt
new file mode 100644
index 000000000000..43ab8f9a5bd3
--- /dev/null
+++ b/ext/opcache/tests/jit/gh24438.phpt
@@ -0,0 +1,40 @@
+--TEST--
+GH-24438 (Tracing JIT preserves indirect arguments on side-trace entry)
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit_buffer_size=64M
+opcache.jit=tracing
+opcache.jit_hot_loop=1
+opcache.jit_hot_func=1
+opcache.jit_hot_return=1
+opcache.jit_hot_side_exit=1
+opcache.jit_max_polymorphic_calls=0
+--FILE--
+<?php
+function byVal($value) {
+ $value = (int) $value + 1000;
+ return $value;
+}
+
+function byRef(&$value) {
+ $value = (int) $value + 1;
+ return $value;
+}
+
+$fns = ['byVal', 'byRef'];
+$arr = [10, 20];
+for ($i = 0; $i < 120; $i++) {
+ $f = $fns[$i % 2];
+ $f($arr[1]);
+ $f($arr[0]);
+}
+
+var_dump($arr[0], $arr[1]);
+?>
+--EXPECT--
+int(70)
+int(80)
diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c
index 004053cc59ff..1235b1fc89fa 100644
--- a/ext/opcache/zend_file_cache.c
+++ b/ext/opcache/zend_file_cache.c
@@ -583,32 +583,13 @@ static void zend_file_cache_serialize_op_array(zend_op_array
*op_arra
}
if (opline->op2_type == IS_CONST) {
SERIALIZE_PTR(opline->op2.zv);
-
- /* See GH-17733. Reset Z_EXTRA_P(op2) of ZEND_INIT_FCALL, which
- * is an offset into the global function table, to avoid calling
- * incorrect functions when environment changes. This, and the
- * equivalent code below, can be removed once proper system ID
- * validation is implemented. */
- if (opline->opcode == ZEND_INIT_FCALL) {
- zval *op2 = opline->op2.zv;
- UNSERIALIZE_PTR(op2);
- Z_EXTRA_P(op2) = 0;
- ZEND_VM_SET_OPCODE_HANDLER(opline);
- }
}
#else
if (opline->op1_type == IS_CONST) {
opline->op1.constant = RT_CONSTANT(opline, opline->op1) - literals;
}
if (opline->op2_type == IS_CONST) {
- zval *op2 = RT_CONSTANT(opline, opline->op2);
- opline->op2.constant = op2 - literals;
-
- /* See GH-17733 and comment above. */
- if (opline->opcode == ZEND_INIT_FCALL) {
- Z_EXTRA_P(op2) = 0;
- ZEND_VM_SET_OPCODE_HANDLER(opline);
- }
+ opline->op2.constant = RT_CONSTANT(opline, opline->op2) - literals;
}
#endif
#if ZEND_USE_ABS_JMP_ADDR
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 87440f68f06a..f2bde9b1fbb5 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -1018,7 +1018,7 @@ PHP_FUNCTION(openssl_spki_new)
}
if (challenge) {
- if (!ASN1_STRING_set(spki->spkac->challenge, challenge, (int)challenge_len)) {
+ if (!ASN1_STRING_set1_data(spki->spkac->challenge, (const unsigned char *) challenge,
challenge_len)) {
php_openssl_store_errors();
php_error_docref(NULL, E_WARNING, "Unable to set challenge data");
goto cleanup;
@@ -1205,7 +1205,8 @@ PHP_FUNCTION(openssl_spki_export_challenge)
goto cleanup;
}
- RETVAL_STRING((const char *)ASN1_STRING_get0_data(spki->spkac->challenge));
+ RETVAL_STRINGL_FAST((const char *)ASN1_STRING_get0_data(spki->spkac->challenge),
+ ASN1_STRING_get_length(spki->spkac->challenge));
goto cleanup;
cleanup:
diff --git a/ext/openssl/openssl_backend_common.c b/ext/openssl/openssl_backend_common.c
index 8ea132a1ab0c..995d836deead 100644
--- a/ext/openssl/openssl_backend_common.c
+++ b/ext/openssl/openssl_backend_common.c
@@ -72,7 +72,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, const X509_NAME *
} else {
/* ASN1_STRING_get0_data(3): Since this is an internal pointer it should not be freed or
modified in any way */
to_add = ASN1_STRING_get0_data(str);
- to_add_len = ASN1_STRING_length(str);
+ to_add_len = ASN1_STRING_get_length(str);
}
if (to_add_len != -1) {
@@ -107,7 +107,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, const X509_NAME *
void php_openssl_add_assoc_asn1_string(zval * val, char * key, const ASN1_STRING * str)
{
- add_assoc_stringl(val, key, (const char *)ASN1_STRING_get0_data(str), ASN1_STRING_length(str));
+ add_assoc_stringl(val, key, (const char *)ASN1_STRING_get0_data(str),
ASN1_STRING_get_length(str));
}
time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
@@ -123,6 +123,7 @@ time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
struct tm thetime;
char * strbuf;
char * thestr;
+ const char *timestr_data;
long gmadjust = 0;
size_t timestr_len;
@@ -131,24 +132,25 @@ time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
return (time_t)-1;
}
- timestr_len = (size_t)ASN1_STRING_length(timestr);
+ timestr_len = ASN1_STRING_get_length(timestr);
+ timestr_data = timestr_len ? (const char *)ASN1_STRING_get0_data(timestr) : "";
- if (timestr_len != strlen((const char *)ASN1_STRING_get0_data(timestr))) {
+ if (memchr(timestr_data, '\0', timestr_len) != NULL) {
php_error_docref(NULL, E_WARNING, "Illegal length in timestamp");
return (time_t)-1;
}
if (timestr_len < 13) {
- php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly",
ASN1_STRING_get0_data(timestr));
+ php_error_docref(NULL, E_WARNING, "Unable to parse time string %.*s correctly",
(int)timestr_len, timestr_data);
return (time_t)-1;
}
if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) {
- php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly",
ASN1_STRING_get0_data(timestr));
+ php_error_docref(NULL, E_WARNING, "Unable to parse time string %.*s correctly",
(int)timestr_len, timestr_data);
return (time_t)-1;
}
- strbuf = estrdup((const char *)ASN1_STRING_get0_data(timestr));
+ strbuf = estrndup(timestr_data, timestr_len);
memset(&thetime, 0, sizeof(thetime));
@@ -636,7 +638,7 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
extension_data = X509_EXTENSION_get_data(extension);
p = ASN1_STRING_get0_data(extension_data);
- length = ASN1_STRING_length(extension_data);
+ length = ASN1_STRING_get_length(extension_data);
if (method->it) {
names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL, &p, length,
ASN1_ITEM_ptr(method->it)));
@@ -658,19 +660,19 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION
*extensio
BIO_puts(bio, "email:");
as = name->d.rfc822Name;
BIO_write(bio, ASN1_STRING_get0_data(as),
- ASN1_STRING_length(as));
+ ASN1_STRING_get_length(as));
break;
case GEN_DNS:
BIO_puts(bio, "DNS:");
as = name->d.dNSName;
BIO_write(bio, ASN1_STRING_get0_data(as),
- ASN1_STRING_length(as));
+ ASN1_STRING_get_length(as));
break;
case GEN_URI:
BIO_puts(bio, "URI:");
as = name->d.uniformResourceIdentifier;
BIO_write(bio, ASN1_STRING_get0_data(as),
- ASN1_STRING_length(as));
+ ASN1_STRING_get_length(as));
break;
default:
/* use builtin print for GEN_OTHERNAME, GEN_X400,
diff --git a/ext/openssl/php_openssl_backend.h b/ext/openssl/php_openssl_backend.h
index fcbb8d42542f..364f27eec23e 100644
--- a/ext/openssl/php_openssl_backend.h
+++ b/ext/openssl/php_openssl_backend.h
@@ -35,6 +35,11 @@
#include <openssl/pkcs12.h>
#include <openssl/cms.h>
+#if OPENSSL_VERSION_NUMBER < 0x40100000L
+#define ASN1_STRING_set1_data(str, data, len) ASN1_STRING_set((str), (data), (int) (len))
+#define ASN1_STRING_get_length(str) ((size_t) ASN1_STRING_length(str))
+#endif
+
#if defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 4
typedef const X509_EXTENSION PHP_OPENSSL_X509_EXTENSION;
#else
diff --git a/ext/openssl/tests/openssl_spki_export_challenge_binary.phpt
b/ext/openssl/tests/openssl_spki_export_challenge_binary.phpt
new file mode 100644
index 000000000000..d5eb8617cb1f
--- /dev/null
+++ b/ext/openssl/tests/openssl_spki_export_challenge_binary.phpt
@@ -0,0 +1,19 @@
+--TEST--
+openssl_spki_export_challenge() preserves empty challenges and embedded NUL bytes
+--EXTENSIONS--
+openssl
+--FILE--
+<?php
+$key = openssl_pkey_get_private('file://' . __DIR__ . '/private_rsa_2048.key');
+
+foreach (["", "challenge", "\0challenge", "challenge\0",
"left\0right"] as $challenge) {
+ $spkac = openssl_spki_new($key, $challenge, OPENSSL_ALGO_SHA256);
+ var_dump(openssl_spki_export_challenge(substr($spkac, 6)) === $challenge);
+}
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/openssl/tests/session_resumption_get_cb_num_tickets_positive.phpt
b/ext/openssl/tests/session_resumption_get_cb_num_tickets_positive.phpt
index 5563b0c22cf8..5c7512d73a35 100644
--- a/ext/openssl/tests/session_resumption_get_cb_num_tickets_positive.phpt
+++ b/ext/openssl/tests/session_resumption_get_cb_num_tickets_positive.phpt
@@ -16,6 +16,7 @@ $serverCode = <<<'CODE'
// Test with num_tickets = 3 (should issue 3 tickets)
$ctx = stream_context_create(['ssl' => [
'local_cert' => '%s',
+ 'session_id_context' => 'num-tickets-test',
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_SERVER,
'num_tickets' => 3, // Issue 3 tickets per connection
]]);
diff --git a/ext/openssl/tests/session_unserialize_repeat.phpt
b/ext/openssl/tests/session_unserialize_repeat.phpt
index b1e33c2d03bd..20084df4fb24 100644
--- a/ext/openssl/tests/session_unserialize_repeat.phpt
+++ b/ext/openssl/tests/session_unserialize_repeat.phpt
@@ -13,6 +13,7 @@ $certFile = __DIR__ . DIRECTORY_SEPARATOR .
'session_unserialize_repeat.pem.tmp'
$serverCode = <<<'CODE'
$serverCtx = stream_context_create(['ssl' => [
'local_cert' => '%s',
+ 'session_id_context' => 'unserialize-repeat-test',
]]);
$server = stream_socket_server('tls://127.0.0.1:0', $errno, $errstr,
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index d55fab02e3ad..8c191df53c1d 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -541,7 +541,7 @@ static bool php_openssl_matches_san_list(
/* TODO: warn ? */
continue;
}
- if ((size_t)ASN1_STRING_length(san->d.dNSName) != strlen((const char*)cert_name)) {
+ if (ASN1_STRING_get_length(san->d.dNSName) != strlen((const char*)cert_name)) {
OPENSSL_free(cert_name);
/* prevent null-byte poisoning*/
continue;
@@ -561,7 +561,7 @@ static bool php_openssl_matches_san_list(
}
OPENSSL_free(cert_name);
} else if (san->type == GEN_IPADD) {
- if (ASN1_STRING_length(san->d.iPAddress) == 4) {
+ if (ASN1_STRING_get_length(san->d.iPAddress) == 4) {
snprintf(ipbuffer, sizeof(ipbuffer), "%d.%d.%d.%d",
ASN1_STRING_get0_data(san->d.iPAddress)[0],
ASN1_STRING_get0_data(san->d.iPAddress)[1],
@@ -575,7 +575,7 @@ static bool php_openssl_matches_san_list(
}
}
#ifdef HAVE_IPV6_SAN
- else if (ASN1_STRING_length(san->d.ip) == 16 && subject_name_is_ipv6) {
+ else if (ASN1_STRING_get_length(san->d.ip) == 16 && subject_name_is_ipv6) {
ipbuffer[0] = 0;
EXPAND_IPV6_ADDRESS(ipbuffer, ASN1_STRING_get0_data(san->d.iPAddress));
if (strcasecmp((const char*)subject_name_ipv6_expanded, (const char*)ipbuffer) == 0) {
@@ -630,7 +630,7 @@ static bool php_openssl_matches_common_name(php_stream *stream, const X509 *peer
return false;
}
name_asn1 = X509_NAME_ENTRY_get_data(name_entry);
- cert_name_len = ASN1_STRING_length(name_asn1);
+ 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_stream_warn(stream, NetworkRecvFailed, "Unable to locate peer certificate CN");