xref: /PHP-8.3/ext/spl/tests/bug65069.phpt (revision 1a9e6895)
1--TEST--
2Bug #65069: GlobIterator fails to access files inside an open_basedir restricted dir
3--FILE--
4<?php
5$file_path = __DIR__;
6// temp dirname used here
7$dirname = "$file_path/bug65069";
8// temp dir created
9mkdir($dirname);
10
11ini_set('open_basedir', $dirname);
12
13// temp files created
14touch("$dirname/wonder12345");
15touch("$dirname/wonder.txt");
16touch("$dirname/file.text");
17
18$spl_glob_it = new \GlobIterator("$dirname/*.txt");
19foreach ($spl_glob_it as $file_info) {
20    echo $file_info->getFilename() . "\n";
21}
22
23$spl_glob_it = new \GlobIterator(dirname(dirname($dirname)) . "/*/*/*");
24foreach ($spl_glob_it as $file_info) {
25    echo $file_info->getFilename() . "\n";
26}
27
28$spl_glob_empty = new \GlobIterator("$dirname/*.php");
29var_dump($spl_glob_empty->count());
30
31// top directory
32var_dump(iterator_to_array(new \GlobIterator(dirname(dirname($dirname)))));
33
34// not existing file
35var_dump(iterator_to_array(new \GlobIterator("$file_path/bug65069-this-will-never-exists")));
36
37
38?>
39--CLEAN--
40<?php
41$file_path = dirname(__FILE__);
42$dirname = "$file_path/bug65069";
43unlink("$dirname/wonder12345");
44unlink("$dirname/wonder.txt");
45unlink("$dirname/file.text");
46rmdir($dirname);
47?>
48--EXPECT--
49wonder.txt
50file.text
51wonder.txt
52wonder12345
53int(0)
54array(0) {
55}
56array(0) {
57}
58