Skip to content

Fix GH-11808: Live filesystem modified by tests (security) #13566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions ext/standard/tests/file/006_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@ require __DIR__ . '/../skipif_root.inc';
<?php
echo "*** Testing error conditions for fileperms(), chmod() ***\n";

/* With standard files and dirs */
var_dump( chmod("/etc/passwd", 0777) );
printf("%o", fileperms("/etc/passwd") );
echo "\n";
clearstatcache();

var_dump( chmod("/etc", 0777) );
printf("%o", fileperms("/etc") );
echo "\n";
clearstatcache();

/* With non-existing file or dir */
var_dump( chmod("/no/such/file/dir", 0777) );
var_dump( fileperms("/no/such/file/dir") );
var_dump( chmod(__DIR__ . "/no/such/file/dir", 0777) );
var_dump( fileperms(__DIR__ . "/no/such/file/dir") );
echo "\n";

echo "\n*** Done ***\n";
Expand All @@ -34,16 +23,8 @@ echo "\n*** Done ***\n";

Warning: chmod(): %s in %s on line %d
bool(false)
100%d44

Warning: chmod(): %s in %s on line %d
bool(false)
40755

Warning: chmod(): No such file or directory in %s on line %d
bool(false)

Warning: fileperms(): stat failed for /no/such/file/dir in %s on line %d
Warning: fileperms(): stat failed for %s/no/such/file/dir in %s on line %d
bool(false)


Expand Down
18 changes: 13 additions & 5 deletions ext/standard/tests/file/chroot_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
chroot()
--SKIPIF--
<?php
chdir("/");
if (!@mkdir("testtmpskipifdir")) {
die("skip for root only");
}
rmdir("testtmpskipifdir");
if (!function_exists("chroot")) {
die("skip chroot() not available");
}
// Skip if not being run by root (files are always readable, writeable and executable)
$filename = @tempnam(__DIR__, 'root_check_');
if (!file_exists($filename)) {
die('WARN Unable to create the "root check" file');
}

$isRoot = fileowner($filename) == 0;

unlink($filename);

if (!$isRoot) {
die('SKIP Must be run as root');
}
?>
--FILE--
<?php
Expand Down
32 changes: 14 additions & 18 deletions ext/standard/tests/file/mkdir-004.phpt
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
--TEST--
recursive mkdir() tests
--SKIPIF--
<?php
chdir("/");
if (!@mkdir("testtmpskipifdir")) {
die("skip for root only");
}
rmdir("testtmpskipifdir");
?>
recursive mkdir() with unclean paths
--FILE--
<?php
chdir(__DIR__);
$dirpath = "./tmp/foo//bar/logs";
mkdir($dirpath, 0777, true);

var_dump(mkdir("/testdir/subdir", 0777, true));
var_dump(rmdir("/testdir/subdir"));
var_dump(rmdir("/testdir"));

echo "Done\n";
if (is_dir($dirpath)) {
echo "Ok.\n";
} else {
echo "Failed.\n";
}
rmdir("./tmp/foo/bar/logs");
rmdir("./tmp/foo/bar/");
rmdir("./tmp/foo/");
rmdir("./tmp/");
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
Done
Ok.
25 changes: 0 additions & 25 deletions ext/standard/tests/file/mkdir-005.phpt

This file was deleted.

20 changes: 0 additions & 20 deletions ext/standard/tests/file/mkdir-006.phpt

This file was deleted.