Skip to content

Commit ae44ab4

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents e328212 + bc30ae4 commit ae44ab4

File tree

6 files changed

+91
-3
lines changed

6 files changed

+91
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
- Curl:
1010
. Fix failing tests due to string changes in libcurl 8.6.0. (Ayesh)
1111

12+
- FPM:
13+
. Fixed bug #75712 (getenv in php-fpm should not read $_ENV, $_SERVER).
14+
(Jakub Zelenka)
15+
1216
- Standard:
1317
. Fixed bug GH-13279 (Instable array during in-place modification in uksort).
1418
(ilutov)

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ PHP_FUNCTION(getenv)
735735

736736
if (!str) {
737737
array_init(return_value);
738-
php_import_environment_variables(return_value);
738+
php_load_environment_variables(return_value);
739739
return;
740740
}
741741

main/php_variables.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
/* for systems that need to override reading of environment variables */
3030
void _php_import_environment_variables(zval *array_ptr);
31+
void _php_load_environment_variables(zval *array_ptr);
3132
PHPAPI void (*php_import_environment_variables)(zval *array_ptr) = _php_import_environment_variables;
33+
PHPAPI void (*php_load_environment_variables)(zval *array_ptr) = _php_load_environment_variables;
3234

3335
PHPAPI void php_register_variable(const char *var, const char *strval, zval *track_vars_array)
3436
{
@@ -632,6 +634,11 @@ void _php_import_environment_variables(zval *array_ptr)
632634
tsrm_env_unlock();
633635
}
634636

637+
void _php_load_environment_variables(zval *array_ptr)
638+
{
639+
php_import_environment_variables(array_ptr);
640+
}
641+
635642
bool php_std_auto_global_callback(char *name, uint32_t name_len)
636643
{
637644
zend_printf("%s\n", name);

main/php_variables.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
BEGIN_EXTERN_C()
3333
void php_startup_auto_globals(void);
3434
extern PHPAPI void (*php_import_environment_variables)(zval *array_ptr);
35+
extern PHPAPI void (*php_load_environment_variables)(zval *array_ptr);
3536
PHPAPI void php_register_variable(const char *var, const char *val, zval *track_vars_array);
3637
/* binary-safe version */
3738
PHPAPI void php_register_variable_safe(const char *var, const char *val, size_t val_len, zval *track_vars_array);

sapi/fpm/fpm/fpm_main.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,21 @@ static void cgi_php_load_env_var(const char *var, unsigned int var_len, char *va
516516
}
517517
/* }}} */
518518

519-
void cgi_php_import_environment_variables(zval *array_ptr) /* {{{ */
519+
static void cgi_php_load_env_var_unfilterd(const char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg)
520+
{
521+
zval *array_ptr = (zval *) arg;
522+
php_register_variable_safe(var, val, val_len, array_ptr);
523+
}
524+
525+
static void cgi_php_load_environment_variables(zval *array_ptr)
526+
{
527+
php_php_import_environment_variables(array_ptr);
528+
529+
fcgi_request *request = (fcgi_request*) SG(server_context);
530+
fcgi_loadenv(request, cgi_php_load_env_var_unfilterd, array_ptr);
531+
}
532+
533+
static void cgi_php_import_environment_variables(zval *array_ptr)
520534
{
521535
fcgi_request *request = NULL;
522536

@@ -542,7 +556,6 @@ void cgi_php_import_environment_variables(zval *array_ptr) /* {{{ */
542556
request = (fcgi_request*) SG(server_context);
543557
fcgi_loadenv(request, cgi_php_load_env_var, array_ptr);
544558
}
545-
/* }}} */
546559

547560
static void sapi_cgi_register_variables(zval *track_vars_array) /* {{{ */
548561
{
@@ -1840,6 +1853,7 @@ consult the installation file that came with this distribution, or visit \n\
18401853
/* make php call us to get _ENV vars */
18411854
php_php_import_environment_variables = php_import_environment_variables;
18421855
php_import_environment_variables = cgi_php_import_environment_variables;
1856+
php_load_environment_variables = cgi_php_load_environment_variables;
18431857

18441858
/* library is already initialized, now init our request */
18451859
request = fpm_init_request(fcgi_fd);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
FPM: bug75712 - getenv should not read from $_ENV and $_SERVER
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
[unconfined]
14+
listen = {{ADDR}}
15+
pm = static
16+
pm.max_children = 1
17+
env[TEST] = test
18+
php_value[register_argc_argv] = on
19+
EOT;
20+
21+
$code = <<<EOT
22+
<?php
23+
24+
var_dump(isset(getenv()['argv']));
25+
var_dump(isset(getenv()['SERVER_NAME']));
26+
var_dump(getenv()['TEST']);
27+
var_dump(isset(getenv()['DTEST']));
28+
var_dump(getenv('DTEST'));
29+
putenv('DTEST=dt');
30+
var_dump(getenv()['DTEST']);
31+
var_dump(getenv('DTEST'));
32+
33+
function notcalled()
34+
{
35+
\$_SERVER['argv'];
36+
}
37+
EOT;
38+
39+
$tester = new FPM\Tester($cfg, $code);
40+
$tester->start();
41+
$tester->expectLogStartNotices();
42+
$tester->request()->expectBody([
43+
'bool(false)',
44+
'bool(true)',
45+
'string(4) "test"',
46+
'bool(false)',
47+
'bool(false)',
48+
'string(2) "dt"',
49+
'string(2) "dt"',
50+
]);
51+
$tester->terminate();
52+
$tester->close();
53+
54+
?>
55+
Done
56+
--EXPECT--
57+
Done
58+
--CLEAN--
59+
<?php
60+
require_once "tester.inc";
61+
FPM\Tester::clean();
62+
?>

0 commit comments

Comments
 (0)