Skip to content

Commit 69dee5c

Browse files
committed
Fixed bug #73342
Directly listen on socket, instead of duping it to STDIN and listening on that.
1 parent 5dd1ef9 commit 69dee5c

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Date:
66
. Fixed bug #76462 (Undefined property: DateInterval::$f). (Anatol)
77

8+
- FPM:
9+
. Fixed bug #73342 (Vulnerability in php-fpm by changing stdin to
10+
non-blocking). (Nikita)
11+
812
22 Jun 2019, PHP 7.1.19
913

1014
- CLI Server:

sapi/fpm/fpm/fpm_children.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static struct fpm_child_s *fpm_child_find(pid_t pid) /* {{{ */
146146
static void fpm_child_init(struct fpm_worker_pool_s *wp) /* {{{ */
147147
{
148148
fpm_globals.max_requests = wp->config->pm_max_requests;
149+
fpm_globals.listening_socket = dup(wp->listening_socket);
149150

150151
if (0 > fpm_stdio_init_child(wp) ||
151152
0 > fpm_log_init_child(wp) ||

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ int fpm_stdio_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
103103
fpm_globals.error_log_fd = -1;
104104
zlog_set_fd(-1);
105105

106-
if (wp->listening_socket != STDIN_FILENO) {
107-
if (0 > dup2(wp->listening_socket, STDIN_FILENO)) {
108-
zlog(ZLOG_SYSERROR, "failed to init child stdio: dup2()");
109-
return -1;
110-
}
111-
}
112106
return 0;
113107
}
114108
/* }}} */
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
FPM: bug73342 - Non-blocking stdin
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 "Before\n";
25+
stream_set_blocking(fopen('php://stdin', 'r'), false);
26+
echo "After\n";
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg, $code);
30+
$tester->start();
31+
$tester->expectLogStartNotices();
32+
$tester->request()->expectBody("Before\nAfter");
33+
$tester->request()->expectBody("Before\nAfter");
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)