Skip to content

Commit 91826fd

Browse files
committed
Fix GH-19320: FPM uid and gid overflow
Closes GH-19321
1 parent 80022c0 commit 91826fd

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

sapi/fpm/fpm/fpm_unix.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,13 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */
354354
if (is_root) {
355355
if (wp->config->user && *wp->config->user) {
356356
if (fpm_unix_is_id(wp->config->user)) {
357-
wp->set_uid = strtoul(wp->config->user, 0, 10);
357+
unsigned long uid_val = strtoul(wp->config->user, 0, 10);
358+
if (uid_val > INT_MAX) {
359+
zlog(ZLOG_ERROR, "[pool %s] invalid user ID '%s': value too large",
360+
wp->config->name, wp->config->user);
361+
return -1;
362+
}
363+
wp->set_uid = (int)uid_val;
358364
pwd = getpwuid(wp->set_uid);
359365
if (pwd) {
360366
wp->set_gid = pwd->pw_gid;
@@ -378,7 +384,13 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */
378384

379385
if (wp->config->group && *wp->config->group) {
380386
if (fpm_unix_is_id(wp->config->group)) {
381-
wp->set_gid = strtoul(wp->config->group, 0, 10);
387+
unsigned long gid_val = strtoul(wp->config->group, 0, 10);
388+
if (gid_val > INT_MAX) {
389+
zlog(ZLOG_ERROR, "[pool %s] invalid group ID '%s': value too large",
390+
wp->config->name, wp->config->group);
391+
return -1;
392+
}
393+
wp->set_gid = (int)gid_val;
382394
} else {
383395
struct group *grp;
384396

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
FPM: gh19320 - config test UID/GID overflow validation
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
FPM\Tester::skipIfNotRoot();
7+
?>
8+
--FILE--
9+
<?php
10+
require_once "tester.inc";
11+
12+
// Test with UID that exceeds INT_MAX (2147483647)
13+
$cfg_uid = <<<EOT
14+
[global]
15+
error_log = {{FILE:LOG}}
16+
[unconfined]
17+
listen = {{ADDR:UDS}}
18+
user = 2147483648
19+
group = root
20+
pm = dynamic
21+
pm.max_children = 5
22+
pm.start_servers = 2
23+
pm.min_spare_servers = 1
24+
pm.max_spare_servers = 3
25+
EOT;
26+
27+
$tester = new FPM\Tester($cfg_uid);
28+
$tester->start();
29+
$tester->expectLogError("\[pool unconfined\] invalid user ID '2147483648': value too large");
30+
31+
// Test with GID that exceeds INT_MAX
32+
$cfg_gid = <<<EOT
33+
[global]
34+
error_log = {{FILE:LOG}}
35+
[unconfined]
36+
listen = {{ADDR:UDS}}
37+
user = root
38+
group = 4294967295
39+
pm = dynamic
40+
pm.max_children = 5
41+
pm.start_servers = 2
42+
pm.min_spare_servers = 1
43+
pm.max_spare_servers = 3
44+
EOT;
45+
46+
$tester = new FPM\Tester($cfg_gid);
47+
$tester->start();
48+
$tester->expectLogError("\[pool unconfined\] invalid group ID '4294967295': value too large");
49+
?>
50+
Done
51+
--EXPECT--
52+
Done
53+
--CLEAN--
54+
<?php
55+
require_once "tester.inc";
56+
FPM\Tester::clean();
57+
?>
58+

0 commit comments

Comments
 (0)