1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3'

* PHP-8.3:
  Fix GH-11808: Live filesystem modified by tests (security)
This commit is contained in:
Niels Dossche
2024-03-01 18:46:39 +01:00
5 changed files with 30 additions and 90 deletions

View File

@@ -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";
@@ -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)

View File

@@ -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

View File

@@ -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.

View File

@@ -1,25 +0,0 @@
--TEST--
recursive mkdir() tests
--SKIPIF--
<?php
chdir("/");
if (!@mkdir("testtmpskipifdir")) {
die("skip for root only");
}
rmdir("testtmpskipifdir");
?>
--FILE--
<?php
chdir("/");
var_dump(mkdir("./testdir/subdir", 0777, true));
var_dump(rmdir("./testdir/subdir"));
var_dump(rmdir("./testdir"));
echo "Done\n";
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
Done

View File

@@ -1,20 +0,0 @@
--TEST--
recursive mkdir() with unclean paths
--FILE--
<?php
chdir(__DIR__);
$dirpath = "./tmp/foo//bar/logs";
mkdir($dirpath, 0777, true);
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--
Ok.