Edit report at https://bugs.php.net/bug.php?id=47358&edit=1
ID: 47358 Updated by: [email protected] Reported by: php at guggemand dot dk Summary: glob returns error, should be empty array() Status: Re-Opened Type: Bug Package: Safe Mode/open_basedir Operating System: FreeBSD 7.1 PHP Version: 5.2.9RC1 Assigned To: pajoye Block user comment: N Private report: N New Comment: I can see the patch commited at 2013-01-08 http://git.php.net/?p=php-src.git;a=history;f=ext/standard/dir.c;hb=HEAD However the 5.5 branch doesn't have it, it seems to be created before 2013-01-08 http://git.php.net/?p=php-src.git;a=history;f=ext/standard/dir.c;hb=refs/heads/PHP-5.5 This way it works in PHP <= 5.5 is returning false or array() on a nonexistent path depending on whether basedir was set or not. In master where the patch is present it returns an empty array disregarding openbasedir setting on linux, but still has difference on windows when the path contains '*' or '?'. I've pushed the test splitted in 5.4/5.5 indicating the 'is state' http://git.php.net/?p=php- src.git;a=blob_plain;f=ext/standard/tests/file/glob_variation3.phpt;hb=refs/heads/PHP-5.4 and into master: http://git.php.net/?p=php- src.git;a=blob_plain;f=ext/standard/tests/file/glob_variation3.phpt;hb=refs/heads/master On master it'll fail on windows because of the platform difference in virtual_file_ex() mentioned above. Previous Comments: ------------------------------------------------------------------------ [2013-08-19 08:28:10] [email protected] Here's a testcase i wrote to ensure it does right across platforms --TEST-- Test glob() function: ensure no platform difference --FILE-- <?php $path = dirname(__FILE__); ini_set('open_basedir', NULL); var_dump(glob("$path/*.none")); ini_set('open_basedir', $path); var_dump(glob("$path/*.none")); ?> ==DONE== --EXPECT-- array(0) { } array(0) { } ==DONE== ------------------------------------------------------------------------ [2013-08-19 08:24:39] [email protected] There are some cases with the platform difference windows x64\Debug_TS\php -n -d open_basedir=C:\php-sdk\phpmaster\vc11\x64\php-src -r "var_dump(glob('C:\php-sdk\phpmaster\vc11\x64\php-src\*.none'));" bool(false) x64\Debug_TS\php -n -r "var_dump(glob('C:\php-sdk\phpmaster\vc11\x64\php-src\*.none'));" array(0) { } linux sapi/cli/php -n -d open_basedir=/home/anatol/dws/src/php-master-ts -r 'var_dump(glob("/home/anatol/dws/src/php-master-ts/*.none"));' array(0) { } sapi/cli/php -n -r 'var_dump(glob("/home/anatol/dws/src/php-master-ts/*.none"));' array(0) { } The cause of this platform difference is that here http://lxr.php.net/xref/PHP_TRUNK/ext/standard/dir.c#495 php_check_open_basedir_ex() subsequently calls virtual_file_ex() http://lxr.php.net/xref/PHP_TRUNK/TSRM/tsrm_virtual_cwd.c#1241 and if the pattern contains '*' or '?', php_check_open_basedir_ex() will return -1 on windows. I've discovered while testing this PR https://github.com/php/php-src/pull/398 which had the same issue. ------------------------------------------------------------------------ [2013-01-08 14:21:58] [email protected] Automatic comment on behalf of [email protected] Revision: http://git.php.net/?p=php-src.git;a=commit;h=50ceeb9f750cecedc483ffc3d3e65a3324e21866 Log: - fix bug #47358, glob returns error, should be empty array() ------------------------------------------------------------------------ [2013-01-08 14:21:57] [email protected] Automatic comment on behalf of [email protected] Revision: http://git.php.net/?p=php-src.git;a=commit;h=2fb7cd30c59345838588ba89ad8b05cc4c34d6dd Log: - fix bug #47358, glob returns error, should be empty array() ------------------------------------------------------------------------ [2012-11-09 14:09:05] manuel-php at mausz dot at Hi Pierre! Please merge your patch asap to php. It works as expected and will fix the following inconsistency: $ php -dopen_basedir=/ -r 'var_dump(glob("/does/not/exist"));' bool(false) $ php -r 'var_dump(glob("/does/not/exist"));' array(0) { } Something to consider is updating the docs to mention returning false if open_basedir restriction is in effect. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=47358 -- Edit this bug report at https://bugs.php.net/bug.php?id=47358&edit=1
