Skip to content

Commit 868a612

Browse files
committed
fpm: ini settings passed through fcgi env should be restored after the request has finished
1 parent feb053a commit 868a612

File tree

3 files changed

+144
-5
lines changed

3 files changed

+144
-5
lines changed

sapi/fpm/fpm/fpm_main.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,6 @@ static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_
13961396
int *mode = (int *)arg;
13971397
char *key;
13981398
char *value = NULL;
1399-
struct key_value_s kv;
14001399

14011400
if (!mode || !arg1) return;
14021401

@@ -1421,10 +1420,7 @@ static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_
14211420
return;
14221421
}
14231422

1424-
kv.key = key;
1425-
kv.value = value;
1426-
kv.next = NULL;
1427-
if (fpm_php_apply_defines_ex(&kv, *mode) == -1) {
1423+
if (zend_alter_ini_entry_chars(Z_STR_P(arg1), Z_STRVAL_P(arg2), Z_STRLEN_P(arg2), *mode, PHP_INI_STAGE_HTACCESS) == FAILURE) {
14281424
zlog(ZLOG_ERROR, "Passing INI directive through FastCGI: unable to set '%s'", key);
14291425
}
14301426
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--TEST--
2+
FPM: test ini settings from fcgi env
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 = dynamic
16+
pm.max_children = 5
17+
pm.start_servers = 1
18+
pm.min_spare_servers = 1
19+
pm.max_spare_servers = 3
20+
EOT;
21+
22+
$code = <<<EOT
23+
<?php
24+
echo "Test Start\n";
25+
var_dump(ini_get('memory_limit'));
26+
echo "Test End\n";
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg, $code);
30+
$tester->start(iniEntries: [ 'memory_limit' => '100M' ]);
31+
$tester->expectLogStartNotices();
32+
$tester->request()->expectBody([
33+
'Test Start',
34+
'string(4) "100M"',
35+
'Test End'
36+
]);
37+
$tester->request(headers: [ "PHP_VALUE" => "memory_limit=300M" ])->expectBody([
38+
'Test Start',
39+
'string(4) "300M"',
40+
'Test End'
41+
]);
42+
# check if the ini value has been reset
43+
$tester->request()->expectBody([
44+
'Test Start',
45+
'string(4) "100M"',
46+
'Test End'
47+
]);
48+
$tester->request(headers: [ "PHP_VALUE" => "memory_limit=" ])->expectBody([
49+
'Test Start',
50+
'string(4) "100M"',
51+
'Test End'
52+
])->expectError('Passing INI directive through FastCGI: unable to set \'memory_limit\'');
53+
$tester->request(headers: [ "PHP_VALUE" => "memory_limit" ])->expectBody([
54+
'Test Start',
55+
'string(4) "100M"',
56+
'Test End'
57+
])->expectError('Passing INI directive through FastCGI: empty value for key \'memory_limit\'');
58+
$tester->terminate();
59+
$tester->expectLogTerminatingNotices();
60+
$tester->close();
61+
62+
?>
63+
Done
64+
--EXPECT--
65+
Done
66+
--CLEAN--
67+
<?php
68+
require_once "tester.inc";
69+
FPM\Tester::clean();
70+
?>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--TEST--
2+
FPM: test HOST= ini sections
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 = dynamic
16+
pm.max_children = 5
17+
pm.start_servers = 1
18+
pm.min_spare_servers = 1
19+
pm.max_spare_servers = 3
20+
EOT;
21+
22+
$ini = <<<EOT
23+
memory_limit = 100M
24+
[HOST=foo.bar]
25+
memory_limit = 200M
26+
[HOST=bar.foo]
27+
memory_limit = 300M
28+
EOT;
29+
30+
$code = <<<EOT
31+
<?php
32+
echo "Test Start\n";
33+
var_dump(ini_get('memory_limit'));
34+
echo "Test End\n";
35+
EOT;
36+
37+
$tester = new FPM\Tester($cfg, $code);
38+
$tester->start(iniEntries: $ini);
39+
$tester->expectLogStartNotices();
40+
$tester->request()->expectBody([
41+
'Test Start',
42+
'string(4) "100M"',
43+
'Test End'
44+
]);
45+
$tester->request(headers: [ "SERVER_NAME" => "foo.bar" ])->expectBody([
46+
'Test Start',
47+
'string(4) "200M"',
48+
'Test End'
49+
]);
50+
$tester->request(headers: [ "SERVER_NAME" => "bar.foo" ])->expectBody([
51+
'Test Start',
52+
'string(4) "300M"',
53+
'Test End'
54+
]);
55+
# check if the ini value has been reset
56+
$tester->request()->expectBody([
57+
'Test Start',
58+
'string(4) "100M"',
59+
'Test End'
60+
]);
61+
$tester->terminate();
62+
$tester->expectLogTerminatingNotices();
63+
$tester->close();
64+
65+
?>
66+
Done
67+
--EXPECT--
68+
Done
69+
--CLEAN--
70+
<?php
71+
require_once "tester.inc";
72+
FPM\Tester::clean();
73+
?>

0 commit comments

Comments
 (0)