From 9bc35f19822026a7835f1baf71418745b180bf50 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 18 Sep 2025 11:57:38 +0200 Subject: [PATCH] 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. Fixes GH-19934 Closes GH-19870 --- NEWS | 1 + Zend/zend_compile.c | 10 +++++----- sapi/cgi/tests/auto_globals_no_jit.phpt | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 sapi/cgi/tests/auto_globals_no_jit.phpt diff --git a/NEWS b/NEWS index 026aac13e69..f56f04dd84f 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ PHP NEWS . Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is configured). (nielsdos) . Fixed bug GH-20002 (Broken build on *BSD with MSAN). (outtersg) + . Fixed bug GH-19934 (CGI with auto_globals_jit=0 causes uouv). (ilutov) - CLI: . Fix useless "Failed to poll event" error logs due to EAGAIN in CLI server diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5d25b396383..3679643fc84 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1938,12 +1938,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(); } diff --git a/sapi/cgi/tests/auto_globals_no_jit.phpt b/sapi/cgi/tests/auto_globals_no_jit.phpt new file mode 100644 index 00000000000..e331709db6d --- /dev/null +++ b/sapi/cgi/tests/auto_globals_no_jit.phpt @@ -0,0 +1,17 @@ +--TEST-- +CGI with auto_globals_jit=0 +--INI-- +auto_globals_jit=0 +--CGI-- +--ENV-- +FOO=BAR +--FILE-- + +--EXPECT-- +string(3) "BAR" +string(3) "BAR" +string(3) "BAR"