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.
This commit is contained in:
@@ -44,6 +44,13 @@ points on a per-request basis during static file serving.
|
||||
</para>
|
||||
</change>
|
||||
|
||||
<change type="bugfix">
|
||||
<para>
|
||||
a segmentation fault might have occurred in the PHP module if
|
||||
fastcgi_finish_request() was used with the "auto_globals_jit" option enabled.
|
||||
</para>
|
||||
</change>
|
||||
|
||||
</changes>
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user