Skip to content

Commit bdf77f0

Browse files
committed
Allow creating $_SERVER from $_ENV, but not $_ENV from $_SERVER.
1 parent 275bba2 commit bdf77f0

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

sapi/cgi/cgi_main.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,15 @@ static void cgi_php_load_env_var(char *var, unsigned int var_len, char *val, uns
624624

625625
static void cgi_php_import_environment_variables(zval *array_ptr)
626626
{
627+
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) != IS_ARRAY) {
628+
zend_is_auto_global_str("_ENV", sizeof("_ENV")-1);
629+
}
630+
627631
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
628-
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) &&
629-
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0
630-
) {
632+
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV])) {
631633
zval_dtor(array_ptr);
632634
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]);
633635
return;
634-
} else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
635-
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) &&
636-
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0
637-
) {
638-
zval_dtor(array_ptr);
639-
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]);
640-
return;
641636
}
642637

643638
/* 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\
19831978
}
19841979
fastcgi = fcgi_is_fastcgi();
19851980
}
1981+
1982+
/* make php call us to get _ENV vars */
1983+
php_php_import_environment_variables = php_import_environment_variables;
1984+
php_import_environment_variables = cgi_php_import_environment_variables;
1985+
19861986
if (fastcgi) {
19871987
/* How many times to run PHP scripts before dying */
19881988
if (getenv("PHP_FCGI_MAX_REQUESTS")) {
@@ -1993,10 +1993,6 @@ consult the installation file that came with this distribution, or visit \n\
19931993
}
19941994
}
19951995

1996-
/* make php call us to get _ENV vars */
1997-
php_php_import_environment_variables = php_import_environment_variables;
1998-
php_import_environment_variables = cgi_php_import_environment_variables;
1999-
20001996
/* library is already initialized, now init our request */
20011997
request = fcgi_init_request(fcgi_fd, NULL, NULL, NULL);
20021998

0 commit comments

Comments
 (0)