Skip to content

Commit 57b4dcb

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix bug #78599 (env_path_info underflow can lead to RCE) (CVE-2019-11043) bump versions after release set versions for release
2 parents 1c9b62f + 4b5cdda commit 57b4dcb

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
@@ -1148,8 +1148,8 @@ static void init_request_info(void)
11481148
path_info = script_path_translated + ptlen;
11491149
tflag = (slen != 0 && (!orig_path_info || strcmp(orig_path_info, path_info) != 0));
11501150
} else {
1151-
path_info = env_path_info ? env_path_info + pilen - slen : NULL;
1152-
tflag = (orig_path_info != path_info);
1151+
path_info = (env_path_info && pilen > slen) ? env_path_info + pilen - slen : NULL;
1152+
tflag = path_info && (orig_path_info != path_info);
11531153
}
11541154

11551155
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
@@ -513,7 +513,7 @@ class Tester
513513
return new Response(null, true);
514514
}
515515
if (is_null($uri)) {
516-
$uri = $this->makeFile('src.php', $this->code);
516+
$uri = $this->makeSourceFile();
517517
}
518518

519519
$params = array_merge(
@@ -538,7 +538,6 @@ class Tester
538538
],
539539
$headers
540540
);
541-
542541
try {
543542
$this->response = new Response(
544543
$this->getClient($address, $connKeepAlive)->request_data($params, false)
@@ -944,6 +943,14 @@ class Tester
944943
return $filePath;
945944
}
946945

946+
/**
947+
* @return string
948+
*/
949+
public function makeSourceFile()
950+
{
951+
return $this->makeFile('src.php', $this->code);
952+
}
953+
947954
/**
948955
* @param string|null $msg
949956
*/

0 commit comments

Comments
 (0)