Skip to content

Commit 065bde1

Browse files
committed
Fix GH-16432: PHP-FPM 8.2 SIGSEGV in fpm_get_status
1 parent 875a9dc commit 065bde1

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- Calendar:
66
. Fixed jdtogregorian overflow. (David Carlier)
77

8+
- FPM:
9+
. Fixed GH-16432 (PHP-FPM 8.2 SIGSEGV in fpm_get_status). (Jakub Zelenka)
10+
811
- PDO:
912
. Fixed memory leak of `setFetchMode()`. (SakiTakamachi)
1013

sapi/fpm/fpm/fpm_status.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ int fpm_status_export_to_zval(zval *status)
6262

6363
/* copy the scoreboard not to bother other processes */
6464
scoreboard = *scoreboard_p;
65-
struct fpm_scoreboard_proc_s procs[scoreboard.nprocs];
65+
struct fpm_scoreboard_proc_s *procs = safe_emalloc(
66+
sizeof(struct fpm_scoreboard_proc_s), scoreboard.nprocs, 0);
6667

6768
struct fpm_scoreboard_proc_s *proc_p;
6869
for(i=0; i<scoreboard.nprocs; i++) {
@@ -131,6 +132,8 @@ int fpm_status_export_to_zval(zval *status)
131132
add_next_index_zval(&fpm_proc_stats, &fpm_proc_stat);
132133
}
133134
add_assoc_zval(status, "procs", &fpm_proc_stats);
135+
efree(procs);
136+
134137
return 0;
135138
}
136139
/* }}} */
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
FPM: GH-16432 - fpm_get_status segfault on high nprocs
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+
log_level = notice
14+
[unconfined]
15+
listen = {{ADDR}}
16+
pm = dynamic
17+
pm.max_children = 12800
18+
pm.start_servers = 1
19+
pm.min_spare_servers = 1
20+
pm.max_spare_servers = 1
21+
catch_workers_output = yes
22+
EOT;
23+
24+
$code = <<<EOT
25+
<?php
26+
var_dump(empty(fpm_get_status()));
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg, $code);
30+
[$sourceFilePath, $scriptName] = $tester->createSourceFileAndScriptName();
31+
$tester->start();
32+
$tester->expectLogStartNotices();
33+
$tester->request()->expectBody('bool(false)');
34+
$tester->terminate();
35+
$tester->expectLogTerminatingNotices();
36+
$tester->close();
37+
38+
?>
39+
Done
40+
--EXPECT--
41+
Done
42+
--CLEAN--
43+
<?php
44+
require_once "tester.inc";
45+
FPM\Tester::clean();
46+
?>

0 commit comments

Comments
 (0)