Skip to content

Commit e4a1b80

Browse files
dwxhbukka
authored andcommitted
Match FPM status pool's expose_php with parent
If an installed php.ini turns expose_php on/off, and an FPM pool overrides that with php_flag[expose_php]=off/on, a status pool created with pm.status_listen in a pool config will have its expose_php reflect the php.ini value, and not the pool config's override. This change looks for an override set in php_flag/php_value/php_admin_flag/php_admin_value and carries that through.
1 parent a14e125 commit e4a1b80

File tree

5 files changed

+124
-2
lines changed

5 files changed

+124
-2
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PHP NEWS
2626
- Fileinfo:
2727
. Upgrade bundled libmagic to 5.43. (Anatol)
2828

29+
- FPM:
30+
. The status.listen shared pool now uses the same php_values (including
31+
expose_php) and php_admin_value as the pool it is shared with. (dwxh)
32+
2933
- JSON:
3034
. Implemented RFC: json_validate()
3135
https://wiki.php.net/rfc/json_validate (Juan Morales)

sapi/fpm/fpm/fpm_conf.c

+14
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,17 @@ int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */
706706
} while (0)
707707
#define FPM_WPC_STR_CP(_cfg, _scfg, _field) FPM_WPC_STR_CP_EX(_cfg, _scfg, _field, _field)
708708

709+
void fpm_conf_apply_kv_array_to_kv_array(struct key_value_s *src, void *dest) {
710+
struct key_value_s *kv;
711+
712+
for (kv = src; kv; kv = kv->next) {
713+
zval k, v;
714+
ZVAL_STRING(&k, kv->key);
715+
ZVAL_STRING(&v, kv->value);
716+
fpm_conf_set_array(&k, &v, &dest, 0);
717+
}
718+
}
719+
709720
static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_wp) { /* {{{ */
710721
struct fpm_worker_pool_config_s *config, *shared_config;
711722
config = fpm_worker_pool_config_alloc();
@@ -738,6 +749,9 @@ static int fpm_worker_pool_shared_status_alloc(struct fpm_worker_pool_s *shared_
738749
FPM_WPC_STR_CP(config, shared_config, group);
739750
FPM_WPC_STR_CP(config, shared_config, pm_status_path);
740751

752+
fpm_conf_apply_kv_array_to_kv_array(shared_config->php_values, (char *)config + WPO(php_values));
753+
fpm_conf_apply_kv_array_to_kv_array(shared_config->php_admin_values, (char *)config + WPO(php_admin_values));
754+
741755
config->pm = PM_STYLE_ONDEMAND;
742756
config->pm_max_children = 2;
743757

sapi/fpm/tests/response.inc

+28-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,20 @@ class Response
107107
*
108108
* @return Response
109109
*/
110-
public function expectHeader($name, $value): Response
110+
public function expectHeader($name, $value, $useRegex = false): Response
111111
{
112-
$this->checkHeader($name, $value);
112+
$this->checkHeader($name, $value, $useRegex);
113+
114+
return $this;
115+
}
116+
117+
/**
118+
* @param string $name
119+
* @return Response
120+
*/
121+
public function expectNoHeader($name)
122+
{
123+
$this->checkNoHeader($name);
113124

114125
return $this;
115126
}
@@ -264,6 +275,21 @@ class Response
264275
return true;
265276
}
266277

278+
/**
279+
* @param string $name
280+
* @return bool
281+
*/
282+
private function checkNoHeader(string $name)
283+
{
284+
$lcName = strtolower($name);
285+
$headers = $this->getHeaders();
286+
if (isset($headers[$lcName])) {
287+
return $this->error("The header $name is present");
288+
}
289+
290+
return true;
291+
}
292+
267293
/**
268294
* Get all headers.
269295
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
FPM: Status pool is inheriting FPM setting overrides test - expose_php = off
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+
pm.status_listen = {{ADDR[status]}}
18+
pm.status_path = /status
19+
php_flag[expose_php] = Off
20+
EOT;
21+
22+
$tester = new FPM\Tester($cfg);
23+
$tester->start();
24+
$tester->expectLogStartNotices();
25+
$response = $tester->request('', [], '/status', '{{ADDR[status]}}');
26+
$response->expectNoHeader('X-Powered-By');
27+
$tester->terminate();
28+
$tester->expectLogTerminatingNotices();
29+
$tester->close();
30+
31+
?>
32+
Done
33+
--EXPECT--
34+
Done
35+
--CLEAN--
36+
<?php
37+
require_once "tester.inc";
38+
FPM\Tester::clean();
39+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
FPM: Status pool is inheriting FPM setting overrides test - expose_php = on
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+
pm.status_listen = {{ADDR[status]}}
18+
pm.status_path = /status
19+
php_flag[expose_php] = On
20+
EOT;
21+
22+
$tester = new FPM\Tester($cfg);
23+
$tester->start();
24+
$tester->expectLogStartNotices();
25+
$response = $tester->request('', [], '/status', '{{ADDR[status]}}');
26+
$response->expectHeader('X-Powered-By', '|^PHP/8|', true);
27+
$tester->terminate();
28+
$tester->expectLogTerminatingNotices();
29+
$tester->close();
30+
31+
?>
32+
Done
33+
--EXPECT--
34+
Done
35+
--CLEAN--
36+
<?php
37+
require_once "tester.inc";
38+
FPM\Tester::clean();
39+
?>

0 commit comments

Comments
 (0)