From: Dmitry Stogov Date: Mon, 13 Nov 2017 15:24:43 +0000 (+0300) Subject: Allow creating $_SERVER from $_ENV, but not $_ENV from $_SERVER. X-Git-Tag: php-7.3.0alpha1~1052 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdf77f02f637bc0efbb55a800be1860279cc5b3e;p=php Allow creating $_SERVER from $_ENV, but not $_ENV from $_SERVER. --- diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 8639027dbc..27f45f93fc 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -624,20 +624,15 @@ static void cgi_php_load_env_var(char *var, unsigned int var_len, char *val, uns static void cgi_php_import_environment_variables(zval *array_ptr) { + if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) != IS_ARRAY) { + zend_is_auto_global_str("_ENV", sizeof("_ENV")-1); + } + if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY && - Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) && - zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0 - ) { + Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV])) { zval_dtor(array_ptr); ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]); return; - } else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY && - Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) && - zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0 - ) { - zval_dtor(array_ptr); - ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]); - return; } /* call php's original import as a catch-all */ @@ -1983,6 +1978,11 @@ consult the installation file that came with this distribution, or visit \n\ } fastcgi = fcgi_is_fastcgi(); } + + /* make php call us to get _ENV vars */ + php_php_import_environment_variables = php_import_environment_variables; + php_import_environment_variables = cgi_php_import_environment_variables; + if (fastcgi) { /* How many times to run PHP scripts before dying */ if (getenv("PHP_FCGI_MAX_REQUESTS")) { @@ -1993,10 +1993,6 @@ consult the installation file that came with this distribution, or visit \n\ } } - /* make php call us to get _ENV vars */ - php_php_import_environment_variables = php_import_environment_variables; - php_import_environment_variables = cgi_php_import_environment_variables; - /* library is already initialized, now init our request */ request = fcgi_init_request(fcgi_fd, NULL, NULL, NULL);