]> granicus.if.org Git - php/commitdiff
Allow creating $_SERVER from $_ENV, but not $_ENV from $_SERVER.
authorDmitry Stogov <dmitry@zend.com>
Mon, 13 Nov 2017 15:24:43 +0000 (18:24 +0300)
committerDmitry Stogov <dmitry@zend.com>
Mon, 13 Nov 2017 15:24:43 +0000 (18:24 +0300)
sapi/cgi/cgi_main.c

index 8639027dbc321115a41c62467be02674e3e04aaf..27f45f93fc9b0e2b02c78bcccb3afd1fffe3b127 100644 (file)
@@ -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);