From 1010592e7841627fe7bad39cd817108c227d0891 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Fri, 27 Nov 2026 13:51:30 -0400 Subject: [PATCH 01/11] sapi: Remove sapi_activate_headers_only (#24051) Introduced in 99c7ddc3a8f9ecf1a3968f6e59dc9d95106bb0c7; previously called in some SAPIs, but the callsites have all been removed for years. --- UPGRADING.INTERNALS | 1 + main/SAPI.c | 39 --------------------------------------- main/SAPI.h | 1 - 3 files changed, 1 insertion(+), 40 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index a2f9bc7f01c9..3ad42019b585 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -65,6 +65,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES . The sapi_get_fd() function was removed. . The sapi_get_target_uid() function was removed. . The sapi_get_target_gid() function was removed. + . The sapi_activate_headers_only() function was removed. . Removed zend_hrtime_posix_clock_id. zend_hrtime() always uses CLOCK_MONOTONIC on POSIX platforms. . The INIT_CLASS_ENTRY_INIT_METHODS() macro, which was previously used as diff --git a/main/SAPI.c b/main/SAPI.c index 4c84a74423b0..f85c0a7c95a8 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -360,45 +360,6 @@ SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len) return 0; } -SAPI_API void sapi_activate_headers_only(void) -{ - if (SG(request_info).headers_read == 1) - return; - SG(request_info).headers_read = 1; - zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), - (void (*)(void *)) sapi_free_header, 0); - SG(sapi_headers).send_default_content_type = 1; - - /* SG(sapi_headers).http_response_code = 200; */ - SG(sapi_headers).http_status_line = NULL; - SG(sapi_headers).mimetype = NULL; - SG(read_post_bytes) = 0; - SG(request_info).request_body = NULL; - SG(request_info).current_user = NULL; - SG(request_info).no_headers = 0; - SG(request_info).post_entry = NULL; - SG(global_request_time) = 0; - - /* - * It's possible to override this general case in the activate() callback, - * if necessary. - */ - if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - if (SG(server_context)) { - SG(request_info).cookie_data = sapi_module.read_cookies(); - if (sapi_module.activate) { - sapi_module.activate(); - } - } - if (sapi_module.input_filter_init ) { - sapi_module.input_filter_init(); - } -} - /* * Called from php_request_startup() for every request. */ diff --git a/main/SAPI.h b/main/SAPI.h index 95a0b86341e4..373f13564e7b 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -226,7 +226,6 @@ SAPI_API char *sapi_getenv(const char *name, size_t name_len); SAPI_API char *sapi_get_default_content_type(void); SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header); SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len); -SAPI_API void sapi_activate_headers_only(void); SAPI_API double sapi_get_request_time(void); END_EXTERN_C() From 04103df7cb7754233b7b589a072a98e81e273f0d Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Fri, 25 Sep 2026 02:15:47 -0400 Subject: [PATCH 02/11] Zend: Reset extended_value of FREE synthesized by DCE DCE rewrites a dead instruction whose operand still needs freeing into a FREE, but kept the instruction's extended_value. After (float) and (array) casts and empty() it has bit 0 set, which ZEND_HANDLE_EXCEPTION reads as ZEND_FREE_ON_RETURN: when a destructor run by that FREE throws, the throw point moves by the FREE's op2, which is (uint32_t)-1, and cleanup_live_vars() frees the operand a second time. Closes GH-25836 --- NEWS | 2 ++ Zend/Optimizer/dce.c | 1 + ext/opcache/tests/opt/dce_029.phpt | 51 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 ext/opcache/tests/opt/dce_029.phpt diff --git a/NEWS b/NEWS index e9c9e3b6f266..136bbc837d8e 100644 --- a/NEWS +++ b/NEWS @@ -165,6 +165,8 @@ PHP NEWS . Fixed function JIT ASSIGN_DIM reporting an undefined value or key out of order, or when the VM does not, on non-array containers. (Jorg Sowa) . Fix JIT register allocation for ASSIGN to traced reference. (ndossche) + . Fixed a double free when a destructor throws while freeing a temporary + whose result the optimizer discarded. (Ilia Alshanetsky) - PDO_Firebird: . Fixed stack buffer overflow with long connection user names, passwords, diff --git a/Zend/Optimizer/dce.c b/Zend/Optimizer/dce.c index 414abe01f96a..88164671af86 100644 --- a/Zend/Optimizer/dce.c +++ b/Zend/Optimizer/dce.c @@ -454,6 +454,7 @@ static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) { opline->opcode = ZEND_FREE; opline->op1.var = EX_NUM_TO_VAR(ssa->vars[free_var].var); opline->op1_type = free_var_type; + opline->extended_value = 0; ssa_op->op1_use = free_var; ssa_op->op1_use_chain = ssa->vars[free_var].use_chain; diff --git a/ext/opcache/tests/opt/dce_029.phpt b/ext/opcache/tests/opt/dce_029.phpt new file mode 100644 index 000000000000..17ab173e1a93 --- /dev/null +++ b/ext/opcache/tests/opt/dce_029.phpt @@ -0,0 +1,51 @@ +--TEST-- +DCE must not keep the replaced instruction's extended_value on a synthesized FREE +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.file_update_protection=0 +opcache.jit=disable +--EXTENSIONS-- +opcache +--FILE-- +a = [new D]; + } + + public function clobber(): int { + $this->a = []; + return 0; + } + + public function test() { + empty(($this->a ?? [])[$this->clobber()]); + } +} + +$c = new C; +try { + $c->test(); +} catch (Exception $e) { + echo $e::class, ": ", $e->getMessage(), "\n"; +} + +$a = []; +for ($i = 0; $i < 10; $i++) { + $a[] = [$i]; +} +echo count($a), "\n"; +?> +--EXPECT-- +Exception: dtor +10 From 604eaea7a2ebc098da53cdf007d475b0d6bffddb Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Fri, 27 Nov 2026 19:32:42 +0100 Subject: [PATCH 03/11] ext/openssl: Fix SNI certs not used on streams sharing a session SSL_CTX Since b1242c32bca a server stream seeded from a session stream shares the parent's SSL_CTX and ignores its own context options. The SNI callback registered on that context looks up the certificate table of the stream doing the handshake, but the table was left only on the parent, so the child always served the default certificate. Give the child its own table that references the parent's per-name contexts. --- NEWS | 2 + .../tests/session_resumption_server_sni.phpt | 78 +++++++++++++++++++ ext/openssl/xp_ssl.c | 30 +++++++ 3 files changed, 110 insertions(+) create mode 100644 ext/openssl/tests/session_resumption_server_sni.phpt diff --git a/NEWS b/NEWS index 74030c5fb8ac..4e17e1c384fd 100644 --- a/NEWS +++ b/NEWS @@ -195,6 +195,8 @@ PHP NEWS `session_new_cb`. (DanielEScherzer) . Fixed bug GH-20920 (LibreSSL build regression with PHP 8.5). (Eugene Gvozdetsky, Theo Buehler, Jakub Zelenka) + . Fixed SNI_server_certs being ignored on a server stream that reuses the + SSL context of a session stream. (Jakub Zelenka) - PDO: . Fixed bug GH-25650 (PDO::query() reports the wrong argument numbers for diff --git a/ext/openssl/tests/session_resumption_server_sni.phpt b/ext/openssl/tests/session_resumption_server_sni.phpt new file mode 100644 index 000000000000..4607d197e301 --- /dev/null +++ b/ext/openssl/tests/session_resumption_server_sni.phpt @@ -0,0 +1,78 @@ +--TEST-- +Server SNI certificate selection on a stream seeded from a session stream +--EXTENSIONS-- +openssl +--FILE-- +saveNewCertAsFileWithKey('cs.php.net', $csFile); +$certificateGenerator->saveNewCertAsFileWithKey('uk.php.net', $ukFile); +$certificateGenerator->saveNewCertAsFileWithKey('us.php.net', $usFile); + +$server = stream_socket_server('tcp://127.0.0.1:0'); +$addr = stream_socket_get_name($server, false); + +function handshake(string $addr, $server, string $peerName, $session, array $serverOptions = []): array +{ + $client = stream_socket_client("tcp://$addr", $errno, $errstr, 5, STREAM_CLIENT_CONNECT, + stream_context_create(['ssl' => [ + 'verify_peer' => false, + 'verify_peer_name' => false, + 'capture_peer_cert' => true, + 'peer_name' => $peerName, + ]])); + $accepted = stream_socket_accept($server); + if ($serverOptions) { + stream_context_set_options($accepted, ['ssl' => $serverOptions]); + } + stream_set_blocking($client, false); + stream_set_blocking($accepted, false); + + $clientDone = $serverDone = 0; + for ($i = 0; $i < 1000 && ($clientDone !== true || $serverDone !== true); $i++) { + if ($clientDone !== true) { + $clientDone = stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + } + if ($serverDone !== true) { + $serverDone = stream_socket_enable_crypto($accepted, true, STREAM_CRYPTO_METHOD_TLS_SERVER, $session); + } + usleep(1000); + } + + $cert = stream_context_get_options($client)['ssl']['peer_certificate']; + var_dump(openssl_x509_parse($cert)['subject']['CN']); + + return [$accepted, $client]; +} + +$parent = handshake($addr, $server, 'uk.php.net', null, [ + 'local_cert' => $csFile, + 'SNI_server_certs' => [ + 'cs.php.net' => $csFile, + 'uk.php.net' => $ukFile, + 'us.php.net' => $usFile, + ], +]); +$child = handshake($addr, $server, 'us.php.net', $parent[0]); + +fclose($parent[0]); +fclose($parent[1]); +unset($parent); + +$grandchild = handshake($addr, $server, 'uk.php.net', $child[0]); +?> +--CLEAN-- + +--EXPECT-- +string(10) "uk.php.net" +string(10) "us.php.net" +string(10) "uk.php.net" diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 72ec45149b86..4f2670519128 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -1580,6 +1580,33 @@ static zend_result php_openssl_enable_server_sni( return SUCCESS; } +static void php_openssl_share_server_sni(php_stream *stream, php_openssl_netstream_data_t *sslsock, + const php_openssl_netstream_data_t *parent_sslsock) +{ + if (sslsock->sni_certs || !parent_sslsock->sni_certs || !parent_sslsock->sni_cert_count) { + return; + } + + bool persistent = php_stream_is_persistent(stream); + unsigned count = 0; + + sslsock->sni_certs = safe_pemalloc(parent_sslsock->sni_cert_count, + sizeof(php_openssl_sni_cert_t), 0, persistent); + + for (unsigned i = 0; i < parent_sslsock->sni_cert_count; i++) { + const php_openssl_sni_cert_t *parent_cert = &parent_sslsock->sni_certs[i]; + if (!parent_cert->ctx) { + continue; + } + SSL_CTX_up_ref(parent_cert->ctx); + sslsock->sni_certs[count].ctx = parent_cert->ctx; + sslsock->sni_certs[count].name = pestrdup(parent_cert->name, persistent); + count++; + } + + sslsock->sni_cert_count = count; +} + static void php_openssl_enable_client_sni(php_stream *stream, php_openssl_netstream_data_t *sslsock) /* {{{ */ { zval *val; @@ -2868,6 +2895,9 @@ static zend_result php_openssl_setup_crypto(php_stream *stream, } SSL_set_ex_data(sslsock->ssl_handle, php_openssl_get_ssl_stream_data_index(), stream); +#ifdef HAVE_TLS_SNI + php_openssl_share_server_sni(stream, sslsock, parent_sslsock); +#endif if (!SSL_set_fd(sslsock->ssl_handle, sslsock->s.socket)) { php_openssl_handle_ssl_error(stream, 0, true); From 3dce06fed4364e0f1f6a38bdb73288d571b637bc Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 2 Nov 2026 08:34:10 -0500 Subject: [PATCH 04/11] ext/pdo_dblib: Release persistent handle error strings at request end The DB-Lib error and message handlers estrdup() server and library text into the connection's pdo_dblib_err. For a persistent connection, errors raised through PDO::exec() and the transaction and lastInsertId() calls stay there until the next statement execute, so a request that ends after such an error leaves pointers into the reset request heap. The next request efree()s them from the message or error handler or the cursor closer, and module shutdown does from the handle closer. Free them from persistent_shutdown once the last PDO object using the connection is released. Closes GH-25159 --- NEWS | 4 ++ ext/pdo_dblib/dblib_driver.c | 11 ++++- ...ersistent_error_state_across_requests.phpt | 44 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 ext/pdo_dblib/tests/persistent_error_state_across_requests.phpt diff --git a/NEWS b/NEWS index 136bbc837d8e..29eed2165300 100644 --- a/NEWS +++ b/NEWS @@ -168,6 +168,10 @@ PHP NEWS . Fixed a double free when a destructor throws while freeing a temporary whose result the optimizer discarded. (Ilia Alshanetsky) +- PDO_DBLIB: + . Fixed a crash on persistent connections after an error raised through + PDO::exec(). (Ilia Alshanetsky) + - PDO_Firebird: . Fixed stack buffer overflow with long connection user names, passwords, charsets, or roles. (Ilia Alshanetsky) diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index dd8fb1c320c6..79fe467bb1e7 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -92,6 +92,15 @@ static void dblib_handle_closer(pdo_dbh_t *dbh) } } +static void dblib_handle_request_shutdown(pdo_dbh_t *dbh) +{ + pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; + + if (H && dbh->refcount <= 2) { + pdo_dblib_err_dtor(&H->err); + } +} + static bool dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; @@ -450,7 +459,7 @@ static const struct pdo_dbh_methods dblib_methods = { dblib_get_attribute, /* get attr */ NULL, /* check liveness */ NULL, /* get driver methods */ - NULL, /* request shutdown */ + dblib_handle_request_shutdown, NULL, /* in transaction, use PDO's internal tracking mechanism */ NULL, /* get gc */ NULL /* scanner */ diff --git a/ext/pdo_dblib/tests/persistent_error_state_across_requests.phpt b/ext/pdo_dblib/tests/persistent_error_state_across_requests.phpt new file mode 100644 index 000000000000..2c72db11e586 --- /dev/null +++ b/ext/pdo_dblib/tests/persistent_error_state_across_requests.phpt @@ -0,0 +1,44 @@ +--TEST-- +PDO_DBLIB: Persistent handle error state does not outlive the request +--EXTENSIONS-- +pdo_dblib +--SKIPIF-- + +--ENV-- +USE_ZEND_ALLOC=0 +USE_TRACKED_ALLOC=1 +--FILE-- + true, PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]); +$stmt = $db->prepare('SELECT 1'); +$stmt->execute(); +var_dump($stmt->fetchColumn()); +$db->exec('SELECT * FROM ' . $_GET['table']); +echo $db->errorInfo()[2], "\n"; +PHP, var_export(__DIR__ . '/config.inc', true)); + +$args = []; +foreach (['pdo', 'pdo_dblib'] as $ext) { + if (file_exists(ini_get('extension_dir') . '/' . $ext . '.' . PHP_SHLIB_SUFFIX)) { + $args[] = '-dextension=' . ini_get('extension_dir') . '/' . $ext . '.' . PHP_SHLIB_SUFFIX; + } +} +php_cli_server_start($code, null, $args); + +foreach (['pdo_dblib_missing_first', 'pdo_dblib_missing_second'] as $table) { + echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/index.php?table=' . $table); +} +?> +--EXPECTF-- +int(1) +Invalid object name 'pdo_dblib_missing_first'. [%d] (severity %d) [] +int(1) +Invalid object name 'pdo_dblib_missing_second'. [%d] (severity %d) [] From cfe29b5e13f99c75db95aa09a9a4220d82715d0a Mon Sep 17 00:00:00 2001 From: lacatoire Date: Sat, 28 Nov 2026 16:20:26 +0800 Subject: [PATCH 05/11] Fix stream context functions rejecting options held by reference (#25719) Dereference the options element of the context parameters before checking its type, so stream_context_create() and stream_context_set_params() accept references to valid options arrays. References to other types still raise a TypeError. Co-authored-by: Gina Peter Banyard Closes #25719 --- NEWS | 2 + ext/standard/streamsfuncs.c | 2 +- ...tream_context_create_params_reference.phpt | 48 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/streams/stream_context_create_params_reference.phpt diff --git a/NEWS b/NEWS index 29eed2165300..574b593c5fe8 100644 --- a/NEWS +++ b/NEWS @@ -286,6 +286,8 @@ PHP NEWS type on 32-bit platforms). (Kamil Tekiela) . Fixed bug GH-25464 (Segfault reading from php://memory after stream_filter_remove() on a read filter). (David Carlier) + . Fixed stream_context_create() and stream_context_set_params() rejecting + an options array passed by reference in the context parameters. (lacatoire) - XSL: . Fixed a crash in XSLTProcessor::transformToDoc() when the return class diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index d1ed12a78c3a..7f10a56136c1 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -952,7 +952,7 @@ static zend_result parse_context_params(php_stream_context *context, HashTable * ZVAL_COPY(&context->notifier->ptr, tmp); context->notifier->dtor = user_space_stream_notifier_dtor; } - if (NULL != (tmp = zend_hash_str_find(params, "options", sizeof("options")-1))) { + if (NULL != (tmp = zend_hash_str_find_deref(params, "options", sizeof("options")-1))) { if (Z_TYPE_P(tmp) == IS_ARRAY) { return parse_context_options(context, Z_ARRVAL_P(tmp)); } else { diff --git a/ext/standard/tests/streams/stream_context_create_params_reference.phpt b/ext/standard/tests/streams/stream_context_create_params_reference.phpt new file mode 100644 index 000000000000..d7afdd3f6f66 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_create_params_reference.phpt @@ -0,0 +1,48 @@ +--TEST-- +stream_context_create() and stream_context_set_params() accept an "options" element held by reference +--FILE-- + ['method' => 'HEAD']]; +$params = ['options' => &$options]; + +try { + $context = stream_context_create(null, $params); + var_dump(stream_context_get_options($context)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +$context = stream_context_create(); +try { + var_dump(stream_context_set_params($context, $params)); + var_dump(stream_context_get_options($context)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +$invalid = 'not an array'; +try { + stream_context_create(null, ['options' => &$invalid]); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +array(1) { + ["http"]=> + array(1) { + ["method"]=> + string(4) "HEAD" + } +} +bool(true) +array(1) { + ["http"]=> + array(1) { + ["method"]=> + string(4) "HEAD" + } +} +TypeError: Invalid stream/context parameter From 22d9227b4fb1609f9a4b6967a9c72da9e7ead8f2 Mon Sep 17 00:00:00 2001 From: lazerg Date: Sat, 28 Nov 2026 06:58:00 +0500 Subject: [PATCH 06/11] ext/snmp: snmp_init_mib() crashes when $mibdirs is omitted or null snmp_init_mib() passed ZSTR_VAL(mibdirs) to netsnmp_ds_set_string() even when $mibdirs was null, so calling it without an argument or with null crashed. It now passes NULL in that case, which makes net-snmp fall back to its default MIB directories, as the RFC describes and as RSHUTDOWN already does. The stub also lacked the = null default even though ZPP treats the argument as optional, so debug builds hit an arginfo/zpp mismatch on snmp_init_mib(). Fix GH-25858 Close GH-25861 --- NEWS | 4 ++++ ext/snmp/snmp.c | 2 +- ext/snmp/snmp.stub.php | 2 +- ext/snmp/snmp_arginfo.h | 6 +++--- ext/snmp/snmp_decl.h | 8 ++++---- ext/snmp/tests/gh25858.phpt | 14 ++++++++++++++ 6 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 ext/snmp/tests/gh25858.phpt diff --git a/NEWS b/NEWS index 2613e6928c95..d14f4ba2d71d 100644 --- a/NEWS +++ b/NEWS @@ -266,6 +266,10 @@ PHP NEWS throws an Error instead of returning an object with unresolved values. (Ilia Alshanetsky) +- SNMP: + . Fixed bug GH-25858 (snmp_init_mib() crashes when $mibdirs is omitted or + null). (lazerg) + - SOAP: . Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key). (lazerg) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 2504d79c0043..2fb68368ef7c 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1853,7 +1853,7 @@ PHP_FUNCTION(snmp_init_mib) } shutdown_mib(); - netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, ZSTR_VAL(mibdirs)); + netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, mibdirs ? ZSTR_VAL(mibdirs) : NULL); #ifdef HAVE_NETSNMP_INIT_MIB netsnmp_init_mib(); #else diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 48199f2a6625..689884a94f46 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -192,7 +192,7 @@ function snmp_get_valueretrieval(): int {} function snmp_read_mib(string $filename): bool {} - function snmp_init_mib(?string $mibdirs): void {} + function snmp_init_mib(?string $mibdirs = null): void {} /** @not-serializable */ class SNMP diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 5e8af709928b..8b642f921c29 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: 9a32b308176289c1b1475524372a69257f464bd4 + * Stub hash: d2c22c27a27f9b1c40c94409236d3068d1b8128a * Has decl header: yes */ #include "zend_attributes.h" @@ -133,8 +133,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_read_mib, 0, 1, _IS_BOOL, 0 ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_init_mib, 0, 1, IS_VOID, 0) - ZEND_ARG_TYPE_INFO(0, mibdirs, IS_STRING, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_init_mib, 0, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mibdirs, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SNMP___construct, 0, 0, 3) diff --git a/ext/snmp/snmp_decl.h b/ext/snmp/snmp_decl.h index f0b7f49d5a37..307485b784aa 100644 --- a/ext/snmp/snmp_decl.h +++ b/ext/snmp/snmp_decl.h @@ -1,8 +1,8 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: 9a32b308176289c1b1475524372a69257f464bd4 */ + * Stub hash: d2c22c27a27f9b1c40c94409236d3068d1b8128a */ -#ifndef ZEND_SNMP_DECL_9a32b308176289c1b1475524372a69257f464bd4_H -#define ZEND_SNMP_DECL_9a32b308176289c1b1475524372a69257f464bd4_H +#ifndef ZEND_SNMP_DECL_d2c22c27a27f9b1c40c94409236d3068d1b8128a_H +#define ZEND_SNMP_DECL_d2c22c27a27f9b1c40c94409236d3068d1b8128a_H typedef enum zend_enum_Snmp_Mib { ZEND_ENUM_Snmp_Mib_AllowUnderscores = 1, @@ -36,4 +36,4 @@ typedef enum zend_enum_Snmp_StringOutput { ZEND_ENUM_Snmp_StringOutput_Hex = 3, } zend_enum_Snmp_StringOutput; -#endif /* ZEND_SNMP_DECL_9a32b308176289c1b1475524372a69257f464bd4_H */ +#endif /* ZEND_SNMP_DECL_d2c22c27a27f9b1c40c94409236d3068d1b8128a_H */ diff --git a/ext/snmp/tests/gh25858.phpt b/ext/snmp/tests/gh25858.phpt new file mode 100644 index 000000000000..305b67242fc9 --- /dev/null +++ b/ext/snmp/tests/gh25858.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-25858 (snmp_init_mib() dereferences NULL when $mibdirs is omitted or null) +--CREDITS-- +OmenP007 +--EXTENSIONS-- +snmp +--FILE-- + +--EXPECT-- +Done From 972d6673fc25046129cdf986fcbf0e22be5412e0 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 25 Nov 2026 06:45:31 +0000 Subject: [PATCH 07/11] ext/phar: phar_archive_delref() double free on shared archive at shutdown. Objects outliving RSHUTDOWN dropped an empty archive at refcount 0 through the already destroyed fname map, while another object still held it. The archive is now left to its last holder. Fix GH-25722 Close GH-25728 --- NEWS | 2 ++ ext/phar/phar.c | 2 +- ext/phar/tests/gh25722.phpt | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ext/phar/tests/gh25722.phpt diff --git a/NEWS b/NEWS index 574b593c5fe8..a37d45717993 100644 --- a/NEWS +++ b/NEWS @@ -207,6 +207,8 @@ PHP NEWS freed private key). (Artem Ukrainskiy) . Fixed use-after-free when unsetting an entry with an open handle. (David Carlier) + . Fixed bug GH-25722 (phar_archive_delref() double free on shared archive at + shutdown). (David Carlier) - POSIX: . Fixed bug GH-25530 (posix_get_last_error() returns an error from a diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 1bdc2d803367..d76b70206e74 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -294,7 +294,7 @@ bool phar_archive_delref(phar_archive_data *phar) /* {{{ */ remove_fname_cache |= phar->flags & PHAR_FILE_COMPRESSION_MASK; } - if (remove_fname_cache) { + if (remove_fname_cache && !PHAR_G(request_ends)) { if (zend_hash_str_del(&(PHAR_G(phar_fname_map)), phar->fname, phar->fname_len) != SUCCESS) { phar_destroy_phar_data(phar); } diff --git a/ext/phar/tests/gh25722.phpt b/ext/phar/tests/gh25722.phpt new file mode 100644 index 000000000000..8ecbb96fa2dd --- /dev/null +++ b/ext/phar/tests/gh25722.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-25722 (Double free of a phar archive shared by objects outliving request shutdown) +--EXTENSIONS-- +phar +--CREDITS-- +sgInnora +--FILE-- + +--EXPECT-- +Done From 233f7691383aef8fc9a26687c79c09d0d1a7edc0 Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Sat, 28 Nov 2026 10:38:19 +0100 Subject: [PATCH 08/11] ext/sockets: Reject NUL bytes in ext/sockets host names (GH-25774) socket_addrinfo_lookup(), socket_bind(), socket_connect(), socket_sendto() and socket_sendmsg() would otherwise resolve only the part before the NUL byte. Closes GH-25774 --- NEWS | 3 ++ ext/sockets/conversions.c | 10 ++++++ ext/sockets/sockets.c | 34 +++++++++++++++++-- .../tests/socket_inet6_address_nul_byte.phpt | 33 ++++++++++++++++++ .../tests/socket_inet_address_nul_byte.phpt | 29 ++++++++++++++++ .../socket_sendmsg_address_nul_byte.phpt | 28 +++++++++++++++ 6 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 ext/sockets/tests/socket_inet6_address_nul_byte.phpt create mode 100644 ext/sockets/tests/socket_inet_address_nul_byte.phpt create mode 100644 ext/sockets/tests/socket_sendmsg_address_nul_byte.phpt diff --git a/NEWS b/NEWS index a37d45717993..73c9b4fefad7 100644 --- a/NEWS +++ b/NEWS @@ -242,6 +242,9 @@ PHP NEWS - Sockets: . Fixed bug GH-25530 (socket_last_error() without a socket returns an error from a previous request). (Artem Ukrainskiy) + . Fixed host names being truncated at NUL bytes in socket_addrinfo_lookup(), + socket_bind(), socket_connect(), socket_sendto() and socket_sendmsg(). + (Jorg Sowa) - Session: . Fixed session upload progress to respect session.use_only_cookies. diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c index 867723f42de2..0e339b946169 100644 --- a/ext/sockets/conversions.c +++ b/ext/sockets/conversions.c @@ -555,6 +555,11 @@ static void from_zval_write_sin_addr(const zval *zaddr_str, char *inaddr, ser_co zend_string *addr_str, *tmp_addr_str; addr_str = zval_get_tmp_string((zval *) zaddr_str, &tmp_addr_str); + if (CHECK_NULL_PATH(ZSTR_VAL(addr_str), ZSTR_LEN(addr_str))) { + do_from_zval_err(ctx, "%s", "must not contain any null bytes"); + zend_tmp_string_release(tmp_addr_str); + return; + } res = php_set_inet_addr(&saddr, ZSTR_VAL(addr_str), ctx->sock); if (res) { memcpy(inaddr, &saddr.sin_addr, sizeof saddr.sin_addr); @@ -605,6 +610,11 @@ static void from_zval_write_sin6_addr(const zval *zaddr_str, char *addr6, ser_co zend_string *addr_str, *tmp_addr_str; addr_str = zval_get_tmp_string((zval *) zaddr_str, &tmp_addr_str); + if (CHECK_NULL_PATH(ZSTR_VAL(addr_str), ZSTR_LEN(addr_str))) { + do_from_zval_err(ctx, "%s", "must not contain any null bytes"); + zend_tmp_string_release(tmp_addr_str); + return; + } res = php_set_inet6_addr(&saddr6, ZSTR_VAL(addr_str), ctx->sock); if (res) { memcpy(addr6, &saddr6.sin6_addr, sizeof saddr6.sin6_addr); diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 6a4a961657d4..cc4740e7bc68 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1198,6 +1198,11 @@ PHP_FUNCTION(socket_connect) sin6.sin6_family = AF_INET6; sin6.sin6_port = htons((unsigned short int)port); + if (CHECK_NULL_PATH(addr, addr_len)) { + zend_argument_value_error(2, "must not contain any null bytes"); + RETURN_THROWS(); + } + if (! php_set_inet6_addr(&sin6, addr, php_sock)) { RETURN_FALSE; } @@ -1217,6 +1222,11 @@ PHP_FUNCTION(socket_connect) sin.sin_family = AF_INET; sin.sin_port = htons((unsigned short int)port); + if (CHECK_NULL_PATH(addr, addr_len)) { + zend_argument_value_error(2, "must not contain any null bytes"); + RETURN_THROWS(); + } + if (! php_set_inet_addr(&sin, addr, php_sock)) { RETURN_FALSE; } @@ -1319,6 +1329,11 @@ PHP_FUNCTION(socket_bind) sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); + if (CHECK_NULL_PATH(addr, addr_len)) { + zend_argument_value_error(2, "must not contain any null bytes"); + RETURN_THROWS(); + } + if (! php_set_inet_addr(sa, addr, php_sock)) { RETURN_FALSE; } @@ -1334,6 +1349,11 @@ PHP_FUNCTION(socket_bind) sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); + if (CHECK_NULL_PATH(addr, addr_len)) { + zend_argument_value_error(2, "must not contain any null bytes"); + RETURN_THROWS(); + } + if (! php_set_inet6_addr(sa, addr, php_sock)) { RETURN_FALSE; } @@ -1617,6 +1637,11 @@ PHP_FUNCTION(socket_sendto) sin.sin_family = AF_INET; sin.sin_port = htons((unsigned short) port); + if (CHECK_NULL_PATH(addr, addr_len)) { + zend_argument_value_error(5, "must not contain any null bytes"); + RETURN_THROWS(); + } + if (! php_set_inet_addr(&sin, addr, php_sock)) { RETURN_FALSE; } @@ -1634,6 +1659,11 @@ PHP_FUNCTION(socket_sendto) sin6.sin6_family = AF_INET6; sin6.sin6_port = htons((unsigned short) port); + if (CHECK_NULL_PATH(addr, addr_len)) { + zend_argument_value_error(5, "must not contain any null bytes"); + RETURN_THROWS(); + } + if (! php_set_inet6_addr(&sin6, addr, php_sock)) { RETURN_FALSE; } @@ -2511,9 +2541,9 @@ PHP_FUNCTION(socket_addrinfo_lookup) php_addrinfo *res; ZEND_PARSE_PARAMETERS_START(1, 3) - Z_PARAM_STR(hostname) + Z_PARAM_PATH_STR(hostname) Z_PARAM_OPTIONAL - Z_PARAM_STRING_OR_NULL(service, service_len) + Z_PARAM_PATH_OR_NULL(service, service_len) Z_PARAM_ARRAY(zhints) ZEND_PARSE_PARAMETERS_END(); diff --git a/ext/sockets/tests/socket_inet6_address_nul_byte.phpt b/ext/sockets/tests/socket_inet6_address_nul_byte.phpt new file mode 100644 index 000000000000..109ec2c8e531 --- /dev/null +++ b/ext/sockets/tests/socket_inet6_address_nul_byte.phpt @@ -0,0 +1,33 @@ +--TEST-- +socket_bind(), socket_connect() and socket_sendto() reject NUL bytes in AF_INET6 addresses +--EXTENSIONS-- +sockets +--SKIPIF-- + +--FILE-- +getMessage(), "\n"; +} +try { + socket_connect($socket, $address, 9); +} catch (ValueError $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +try { + socket_sendto($socket, "x", 1, 0, $address, 9); +} catch (ValueError $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +?> +--EXPECT-- +ValueError: socket_bind(): Argument #2 ($address) must not contain any null bytes +ValueError: socket_connect(): Argument #2 ($address) must not contain any null bytes +ValueError: socket_sendto(): Argument #5 ($address) must not contain any null bytes diff --git a/ext/sockets/tests/socket_inet_address_nul_byte.phpt b/ext/sockets/tests/socket_inet_address_nul_byte.phpt new file mode 100644 index 000000000000..c0f7134e1ff3 --- /dev/null +++ b/ext/sockets/tests/socket_inet_address_nul_byte.phpt @@ -0,0 +1,29 @@ +--TEST-- +socket_bind(), socket_connect() and socket_sendto() reject NUL bytes in AF_INET addresses +--EXTENSIONS-- +sockets +--FILE-- +getMessage(), "\n"; +} +try { + socket_connect($socket, $address, 9); +} catch (ValueError $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +try { + socket_sendto($socket, "x", 1, 0, $address, 9); +} catch (ValueError $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +?> +--EXPECT-- +ValueError: socket_bind(): Argument #2 ($address) must not contain any null bytes +ValueError: socket_connect(): Argument #2 ($address) must not contain any null bytes +ValueError: socket_sendto(): Argument #5 ($address) must not contain any null bytes diff --git a/ext/sockets/tests/socket_sendmsg_address_nul_byte.phpt b/ext/sockets/tests/socket_sendmsg_address_nul_byte.phpt new file mode 100644 index 000000000000..76dfefeeae01 --- /dev/null +++ b/ext/sockets/tests/socket_sendmsg_address_nul_byte.phpt @@ -0,0 +1,28 @@ +--TEST-- +socket_sendmsg() rejects NUL bytes in addresses +--EXTENSIONS-- +sockets +--SKIPIF-- + +--FILE-- + ["addr" => "127.0.0.1\0.example.com", "port" => 9], + "iov" => ["x"], +], 0)); + +$socket = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP); +var_dump(socket_sendmsg($socket, [ + "name" => ["addr" => "::1\0.example.com", "port" => 9], + "iov" => ["x"], +], 0)); +?> +--EXPECTF-- +Warning: socket_sendmsg(): error converting user data (path: msghdr > name > addr): must not contain any null bytes in %s on line %d +bool(false) + +Warning: socket_sendmsg(): error converting user data (path: msghdr > name > addr): must not contain any null bytes in %s on line %d +bool(false) From 8096dc69b5237b8d32fcb4bdc2fc80a2f075902a Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Fri, 27 Nov 2026 07:24:49 -0500 Subject: [PATCH 09/11] ext/standard: Release lc_needle on OOM in php_str_to_str_i_ex() When zend_string_safe_falloc() fails under memory_limit, php_str_to_str_i_ex() returned NULL without releasing the lowercased needle. Closes GH-25848 --- ext/standard/string.c | 1 + .../tests/strings/str_ireplace_oom.phpt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ext/standard/tests/strings/str_ireplace_oom.phpt diff --git a/ext/standard/string.c b/ext/standard/string.c index 8b0f8ec572bb..e7ce42d38827 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -3352,6 +3352,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, const char *lc_ha if (str_len > ZSTR_LEN(lc_needle)) { new_str = zend_string_safe_falloc(count, str_len - ZSTR_LEN(lc_needle), ZSTR_LEN(haystack), 0, /* fallible */ true); if (UNEXPECTED(!new_str)) { + zend_string_release_ex(lc_needle, 0); return NULL; } } else { diff --git a/ext/standard/tests/strings/str_ireplace_oom.phpt b/ext/standard/tests/strings/str_ireplace_oom.phpt new file mode 100644 index 000000000000..3991f96cc7a5 --- /dev/null +++ b/ext/standard/tests/strings/str_ireplace_oom.phpt @@ -0,0 +1,23 @@ +--TEST-- +str_ireplace() releases lowercased needle on OOM +--SKIPIF-- + +--INI-- +memory_limit=4M +--FILE-- + +--EXPECTF-- +Fatal error: Allowed memory size of 4194304 bytes exhausted %S(tried to allocate %d bytes) in %s on line %d +bool(true) From 16c466297b4ebf62b511e060d227b62f6724d4a7 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 26 Nov 2026 18:21:57 -0500 Subject: [PATCH 10/11] ext/opcache: Do not drop QM_ASSIGN of IS_VAR before ZEND_RETURN Keep the dereferencing QM_ASSIGN when its source is IS_VAR. ZEND_RETURN only accepts CONST, TMP, and CV, so folding the assignment into the return can produce an invalid opcode for by-reference assignments or list destructuring. Fixes GH-25756 Closes GH-25814 --- NEWS | 2 + Zend/Optimizer/block_pass.c | 2 +- ext/opcache/tests/gh25756.phpt | 99 ++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 ext/opcache/tests/gh25756.phpt diff --git a/NEWS b/NEWS index 2dfdf7e9b217..b8b694d06dd5 100644 --- a/NEWS +++ b/NEWS @@ -186,6 +186,8 @@ PHP NEWS . Fix JIT register allocation for ASSIGN to traced reference. (ndossche) . Fixed a double free when a destructor throws while freeing a temporary whose result the optimizer discarded. (Ilia Alshanetsky) + . Fixed bug GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a + reference in a return). (Ilia Alshanetsky, Pratik Bhujel) - OpenSSL: . Fixed bug GH-25172 (TLS session reuse shares request-lifetime callback diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c index 0601994479e6..f790c3bf620d 100644 --- a/Zend/Optimizer/block_pass.c +++ b/Zend/Optimizer/block_pass.c @@ -910,7 +910,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array case ZEND_RETURN: if (opline->op1_type == IS_TMP_VAR) { src = VAR_SOURCE(opline->op1); - if (src && src->opcode == ZEND_QM_ASSIGN) { + if (src && src->opcode == ZEND_QM_ASSIGN && src->op1_type != IS_VAR) { zend_op *op = src + 1; bool optimize = true; diff --git a/ext/opcache/tests/gh25756.phpt b/ext/opcache/tests/gh25756.phpt new file mode 100644 index 000000000000..30fb73083c4d --- /dev/null +++ b/ext/opcache/tests/gh25756.phpt @@ -0,0 +1,99 @@ +--TEST-- +GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a reference in a return) +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--FILE-- +p = &$b; +} + +function test_assign_dim_ref() { + $b = 'dim_val'; + $arr = []; + return $arr[0] = &$b; +} + +class StaticPropHolder { + public static $p; +} + +function test_assign_static_prop_ref(&$b) { + return StaticPropHolder::$p = &$b; +} + +function test_list_by_ref() { + $arr = ['list_val']; + return [&$a] = $arr; +} + +function test_ternary_assign_ref(bool $cond) { + $b = 'ternary_val'; + return $cond ? ($a = &$b) : 'other'; +} + +function test_match_assign_ref(bool $cond) { + $b = 'match_val'; + return match ($cond) { + true => $a = &$b, + default => 'other', + }; +} + +function test_typed_assign_ref(): string { + $b = 'typed_val'; + return $a = &$b; +} + +$obj = new stdClass(); +$obj_src = 'obj_prop'; +$obj_ret = test_assign_obj_ref($obj, $obj_src); +$obj_src = 'obj_changed'; + +$static_src = 'static_prop'; +$static_ret = test_assign_static_prop_ref($static_src); +$static_src = 'static_changed'; + +$arrow_src = 'arrow_val'; +$arrow = fn() => $a = &$arrow_src; + +echo "1: ", test_assign_ref(), "\n"; +echo "2: ", test_assign_func_ref(), "\n"; +echo "3: ", $obj_ret, " / ", $obj->p, "\n"; +echo "4: ", test_assign_dim_ref(), "\n"; +echo "5: ", $static_ret, " / ", StaticPropHolder::$p, "\n"; +echo "6: ", implode(',', test_list_by_ref()), "\n"; +echo "7: ", test_ternary_assign_ref(true), "\n"; +echo "8: ", test_match_assign_ref(true), "\n"; +echo "9: ", test_typed_assign_ref(), "\n"; +echo "10: ", $arrow(), "\n"; +?> +--EXPECT-- +1: success +2: from_func +3: obj_prop / obj_changed +4: dim_val +5: static_prop / static_changed +6: list_val +7: ternary_val +8: match_val +9: typed_val +10: arrow_val From 4d09bb82d5041537df5b0d980bd1e7e4f99cc67e Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sat, 28 Nov 2026 10:25:00 -0500 Subject: [PATCH 11/11] Zend: Accumulate parsed integer locally in _zend_handle_numeric_str_ex() _zend_handle_numeric_str_ex() updated *idx on every digit. Because key is a const char * that may alias *idx, GCC loaded and stored *idx on every loop iteration. Accumulate into a local zend_ulong and store *idx once at the end of the string. --- Zend/zend_hash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 59be1972cc44..50d4bd044ab3 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -3490,10 +3490,11 @@ ZEND_ATTRIBUTE_NONNULL ZEND_API bool ZEND_FASTCALL _zend_handle_numeric_str_ex(c *tmp > '2')) { /* overflow */ return 0; } - *idx = (*tmp - '0'); + zend_ulong val = *tmp - '0'; while (1) { ++tmp; if (tmp == end) { + *idx = val; if (*key == '-') { if (*idx-1 > ZEND_LONG_MAX) { /* overflow */ return 0; @@ -3505,7 +3506,7 @@ ZEND_ATTRIBUTE_NONNULL ZEND_API bool ZEND_FASTCALL _zend_handle_numeric_str_ex(c return 1; } if (*tmp <= '9' && *tmp >= '0') { - *idx = (*idx * 10) + (*tmp - '0'); + val = (val * 10) + (*tmp - '0'); } else { return 0; }