Skip to content

Commit 6bef57f

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix bug #78599 (env_path_info underflow can lead to RCE) (CVE-2019-11043) bump versions after release set versions for release
2 parents 084d401 + 59953ef commit 6bef57f

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

sapi/fpm/fpm/fpm_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,8 +1138,8 @@ static void init_request_info(void)
11381138
path_info = script_path_translated + ptlen;
11391139
tflag = (slen != 0 && (!orig_path_info || strcmp(orig_path_info, path_info) != 0));
11401140
} else {
1141-
path_info = env_path_info ? env_path_info + pilen - slen : NULL;
1142-
tflag = (orig_path_info != path_info);
1141+
path_info = (env_path_info && pilen > slen) ? env_path_info + pilen - slen : NULL;
1142+
tflag = path_info && (orig_path_info != path_info);
11431143
}
11441144

11451145
if (tflag) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
FPM: bug78599 - env_path_info underflow - CVE-2019-11043
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(\$_SERVER["PATH_INFO"]);
26+
echo "Test End\n";
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg, $code);
30+
$tester->start();
31+
$tester->expectLogStartNotices();
32+
$uri = $tester->makeSourceFile();
33+
$tester
34+
->request(
35+
'',
36+
[
37+
'SCRIPT_FILENAME' => $uri . "/" . str_repeat('A', 35),
38+
'PATH_INFO' => '',
39+
'HTTP_HUI' => str_repeat('PTEST', 1000),
40+
],
41+
$uri
42+
)
43+
->expectBody(
44+
[
45+
'Test Start',
46+
'string(0) ""',
47+
'Test End'
48+
]
49+
);
50+
$tester->terminate();
51+
$tester->close();
52+
53+
?>
54+
Done
55+
--EXPECT--
56+
Done
57+
--CLEAN--
58+
<?php
59+
require_once "tester.inc";
60+
FPM\Tester::clean();
61+
?>

sapi/fpm/tests/tester.inc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class Tester
509509
return new Response(null, true);
510510
}
511511
if (is_null($uri)) {
512-
$uri = $this->makeFile('src.php', $this->code);
512+
$uri = $this->makeSourceFile();
513513
}
514514

515515
$params = array_merge(
@@ -534,7 +534,6 @@ class Tester
534534
],
535535
$headers
536536
);
537-
538537
try {
539538
$this->response = new Response(
540539
$this->getClient($address, $connKeepAlive)->request_data($params, false)
@@ -940,6 +939,14 @@ class Tester
940939
return $filePath;
941940
}
942941

942+
/**
943+
* @return string
944+
*/
945+
public function makeSourceFile()
946+
{
947+
return $this->makeFile('src.php', $this->code);
948+
}
949+
943950
/**
944951
* @param string|null $msg
945952
*/

0 commit comments

Comments
 (0)