summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_php_sapi.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2021-05-07 07:46:25 +0300
committerValentin Bartenev <vbart@nginx.com>2021-05-07 07:46:25 +0300
commitb0e32bc015f8eb146e745b7184549e15c6657f85 (patch)
treed6e68c130558c35a77fcb35979f707ff0d020a72 /src/nxt_php_sapi.c
parent6703b68ed00e7cc8132c0aaf3049ed30889de8a8 (diff)
downloadunit-b0e32bc015f8eb146e745b7184549e15c6657f85.tar.gz
unit-b0e32bc015f8eb146e745b7184549e15c6657f85.tar.bz2
PHP: forced initialization of $_SERVER in fastcgi_finish_request().
The "auto_globals_jit" PHP option postponed the initialization of the $_SERVER global variable until the script using it had been loaded (e. g. via the "include" expression). As a result, nxt_php_register_variables() could be called after fastcgi_finish_request() had finished the request and nulled ctx->req, which thus caused a segmentation fault.
Diffstat (limited to 'src/nxt_php_sapi.c')
-rw-r--r--src/nxt_php_sapi.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c
index 8fbe7f65..23c148c8 100644
--- a/src/nxt_php_sapi.c
+++ b/src/nxt_php_sapi.c
@@ -163,7 +163,8 @@ static const zend_function_entry nxt_php_ext_functions[] = {
};
-zif_handler nxt_php_chdir_handler;
+zif_handler nxt_php_chdir_handler;
+zend_auto_global *nxt_php_server_ag;
static zend_module_entry nxt_php_unit_module = {
@@ -211,6 +212,7 @@ ZEND_NAMED_FUNCTION(nxt_php_chdir)
PHP_FUNCTION(fastcgi_finish_request)
{
+ zend_auto_global *ag;
nxt_php_run_ctx_t *ctx;
if (nxt_slow_path(zend_parse_parameters_none() == FAILURE)) {
@@ -240,6 +242,16 @@ PHP_FUNCTION(fastcgi_finish_request)
php_header(TSRMLS_C);
#endif
+ ag = nxt_php_server_ag;
+
+ if (ag->armed) {
+#ifdef NXT_PHP7
+ ag->armed = ag->auto_global_callback(ag->name);
+#else
+ ag->armed = ag->auto_global_callback(ag->name, ag->name_len TSRMLS_CC);
+#endif
+ }
+
nxt_unit_request_done(ctx->req, NXT_UNIT_OK);
ctx->req = NULL;
@@ -411,6 +423,19 @@ nxt_php_setup(nxt_task_t *task, nxt_process_t *process,
nxt_php_set_options(task, value, ZEND_INI_USER);
}
+#ifdef NXT_PHP7
+ nxt_php_server_ag = zend_hash_str_find_ptr(CG(auto_globals), "_SERVER",
+ nxt_length("_SERVER"));
+#else
+ zend_hash_quick_find(CG(auto_globals), "_SERVER", sizeof("_SERVER"),
+ zend_hash_func("_SERVER", sizeof("_SERVER")),
+ (void **) &nxt_php_server_ag);
+#endif
+ if (nxt_slow_path(nxt_php_server_ag == NULL)) {
+ nxt_alert(task, "failed to find $_SERVER auto global");
+ return NXT_ERROR;
+ }
+
return NXT_OK;
}