Skip to content

Commit 3c98b1d

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-11808: Live filesystem modified by tests (security)
2 parents 7d0e2d8 + dfd37c7 commit 3c98b1d

File tree

5 files changed

+30
-90
lines changed

5 files changed

+30
-90
lines changed

ext/standard/tests/file/006_error.phpt

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@ require __DIR__ . '/../skipif_root.inc';
1111
<?php
1212
echo "*** Testing error conditions for fileperms(), chmod() ***\n";
1313

14-
/* With standard files and dirs */
15-
var_dump( chmod("/etc/passwd", 0777) );
16-
printf("%o", fileperms("/etc/passwd") );
17-
echo "\n";
18-
clearstatcache();
19-
20-
var_dump( chmod("/etc", 0777) );
21-
printf("%o", fileperms("/etc") );
22-
echo "\n";
23-
clearstatcache();
24-
2514
/* With non-existing file or dir */
26-
var_dump( chmod("/no/such/file/dir", 0777) );
27-
var_dump( fileperms("/no/such/file/dir") );
15+
var_dump( chmod(__DIR__ . "/no/such/file/dir", 0777) );
16+
var_dump( fileperms(__DIR__ . "/no/such/file/dir") );
2817
echo "\n";
2918

3019
echo "\n*** Done ***\n";
@@ -34,16 +23,8 @@ echo "\n*** Done ***\n";
3423

3524
Warning: chmod(): %s in %s on line %d
3625
bool(false)
37-
100%d44
38-
39-
Warning: chmod(): %s in %s on line %d
40-
bool(false)
41-
40755
42-
43-
Warning: chmod(): No such file or directory in %s on line %d
44-
bool(false)
4526

46-
Warning: fileperms(): stat failed for /no/such/file/dir in %s on line %d
27+
Warning: fileperms(): stat failed for %s/no/such/file/dir in %s on line %d
4728
bool(false)
4829

4930

ext/standard/tests/file/chroot_001.phpt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22
chroot()
33
--SKIPIF--
44
<?php
5-
chdir("/");
6-
if (!@mkdir("testtmpskipifdir")) {
7-
die("skip for root only");
8-
}
9-
rmdir("testtmpskipifdir");
105
if (!function_exists("chroot")) {
116
die("skip chroot() not available");
127
}
8+
// Skip if not being run by root (files are always readable, writeable and executable)
9+
$filename = @tempnam(__DIR__, 'root_check_');
10+
if (!file_exists($filename)) {
11+
die('WARN Unable to create the "root check" file');
12+
}
13+
14+
$isRoot = fileowner($filename) == 0;
15+
16+
unlink($filename);
17+
18+
if (!$isRoot) {
19+
die('SKIP Must be run as root');
20+
}
1321
?>
1422
--FILE--
1523
<?php
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
--TEST--
2-
recursive mkdir() tests
3-
--SKIPIF--
4-
<?php
5-
chdir("/");
6-
if (!@mkdir("testtmpskipifdir")) {
7-
die("skip for root only");
8-
}
9-
rmdir("testtmpskipifdir");
10-
?>
2+
recursive mkdir() with unclean paths
113
--FILE--
124
<?php
5+
chdir(__DIR__);
6+
$dirpath = "./tmp/foo//bar/logs";
7+
mkdir($dirpath, 0777, true);
138

14-
var_dump(mkdir("/testdir/subdir", 0777, true));
15-
var_dump(rmdir("/testdir/subdir"));
16-
var_dump(rmdir("/testdir"));
17-
18-
echo "Done\n";
9+
if (is_dir($dirpath)) {
10+
echo "Ok.\n";
11+
} else {
12+
echo "Failed.\n";
13+
}
14+
rmdir("./tmp/foo/bar/logs");
15+
rmdir("./tmp/foo/bar/");
16+
rmdir("./tmp/foo/");
17+
rmdir("./tmp/");
1918
?>
2019
--EXPECT--
21-
bool(true)
22-
bool(true)
23-
bool(true)
24-
Done
20+
Ok.

ext/standard/tests/file/mkdir-005.phpt

Lines changed: 0 additions & 25 deletions
This file was deleted.

ext/standard/tests/file/mkdir-006.phpt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)