php-src/ext/standard/tests/file/006_error.phpt
Niels Dossche 7c8a3e426e Fix GH-11808: Live filesystem modified by tests (security)
There's a test that tries to make /etc world-writable, and asserts that
it fails. Although this test is guarded by a root user check, there are
situations where you don't need to be root to be able to do this.
This may thus have unwanted effects on your live filesystem.

The simple solution is to remove that part of the test. It doesn't
really add value anyway: we're trying to test the chmod error path, but
that exact same error path can be reached with any failure condition
that the kernel gives. For example, trying to chmod a non-existent file
will trigger the same code path.

While at it, also prefix the test path for the non-existent file such
that we don't accidentally modify the filesystem.

The chroot now has a better root-user check, that will not modify the
filesystem.

Other root-modifying mkdir tests were removed because they added no
value either.

Closes GH-13566.
2024-03-01 18:45:54 +01:00

31 lines
689 B
PHP

--TEST--
Test fileperms(), chmod() functions: error conditions
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Not on Windows');
}
require __DIR__ . '/../skipif_root.inc';
?>
--FILE--
<?php
echo "*** Testing error conditions for fileperms(), chmod() ***\n";
/* With non-existing file or dir */
var_dump( chmod(__DIR__ . "/no/such/file/dir", 0777) );
var_dump( fileperms(__DIR__ . "/no/such/file/dir") );
echo "\n";
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing error conditions for fileperms(), chmod() ***
Warning: chmod(): %s in %s on line %d
bool(false)
Warning: fileperms(): stat failed for %s/no/such/file/dir in %s on line %d
bool(false)
*** Done ***