1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix CGI with auto_globals_jit=0

In CGI, php_auto_globals_create_server() (i.e. auto_global_callback() here)
initializes $_ENV to reuse for $_SERVER. However, because $_SERVER is
constructed first, we have not yet initialized auto_global->armed of the $_ENV
global. Split the loop into initialization and constructor phases.

Closes GH-19870
This commit is contained in:
Ilija Tovilo
2025-09-18 11:57:38 +02:00
parent 7a63dcc3ca
commit 8b51bcaa18
2 changed files with 22 additions and 5 deletions

View File

@@ -2014,12 +2014,12 @@ ZEND_API void zend_activate_auto_globals(void) /* {{{ */
zend_auto_global *auto_global;
ZEND_HASH_MAP_FOREACH_PTR(CG(auto_globals), auto_global) {
if (auto_global->jit) {
auto_global->armed = 1;
} else if (auto_global->auto_global_callback) {
auto_global->armed = auto_global->jit || auto_global->auto_global_callback;
} ZEND_HASH_FOREACH_END();
ZEND_HASH_MAP_FOREACH_PTR(CG(auto_globals), auto_global) {
if (auto_global->armed && !auto_global->jit) {
auto_global->armed = auto_global->auto_global_callback(auto_global->name);
} else {
auto_global->armed = 0;
}
} ZEND_HASH_FOREACH_END();
}

View File

@@ -0,0 +1,17 @@
--TEST--
CGI with auto_globals_jit=0
--INI--
auto_globals_jit=0
--CGI--
--ENV--
FOO=BAR
--FILE--
<?php
var_dump($_SERVER['FOO']);
var_dump($_ENV['FOO']);
var_dump(getenv('FOO'));
?>
--EXPECT--
string(3) "BAR"
string(3) "BAR"
string(3) "BAR"