Skip to content

Commit e5ab9f4

Browse files
committedAug 2, 2022
Fix bug #65489: glob() basedir check is inconsistent
This removes the inconsistent and incorrectly working open basedir check on pattern in glob. It means that an empty array will be returned even if the whole pattern is outside the open basedir restriction.
1 parent db84e44 commit e5ab9f4

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed
 

‎NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PHP NEWS
88
. Removed redundant RuntimeExceptions from Randomizer methods. The
99
exceptions thrown by the engines will be exposed directly. (timwolla)
1010

11+
- Standard:
12+
. Fixed bug #65489 (glob() basedir check is inconsistent). (Jakub Zelenka)
13+
1114
04 Aug 2022, PHP 8.2.0beta2
1215

1316
- Core:

‎UPGRADING

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ PHP 8.2 UPGRADE NOTES
3939
further details.
4040

4141
- Standard:
42+
. glob() returns empty array if all paths are restricted by open_basedir.
43+
Previously the error was returned but that behavior was not consistent and
44+
did not work correctly for all patterns.
4245
. strtolower() and strtoupper() are no longer locale-sensitive. They now
4346
perform ASCII case conversion, as if the locale were "C". Use
4447
mb_strtolower() if you want localized case conversion. Similarly, stristr,

‎ext/standard/dir.c

-12
Original file line numberDiff line numberDiff line change
@@ -471,18 +471,6 @@ PHP_FUNCTION(glob)
471471
if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
472472
#ifdef GLOB_NOMATCH
473473
no_results:
474-
#endif
475-
#ifndef PHP_WIN32
476-
/* Paths containing '*', '?' and some other chars are
477-
illegal on Windows but legit on other platforms. For
478-
this reason the direct basedir check against the glob
479-
query is senseless on windows. For instance while *.txt
480-
is a pretty valid filename on EXT3, it's invalid on NTFS. */
481-
if (PG(open_basedir) && *PG(open_basedir)) {
482-
if (php_check_open_basedir_ex(pattern, 0)) {
483-
RETURN_FALSE;
484-
}
485-
}
486474
#endif
487475
array_init(return_value);
488476
return;

‎ext/standard/tests/file/bug41655_1.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ var_dump($a);
1717
echo "Done\n";
1818
?>
1919
--EXPECT--
20-
bool(false)
20+
array(0) {
21+
}
2122
Done

‎ext/standard/tests/file/glob_variation5.phpt

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Test glob() function: ensure no platform difference, variation 3
33
--SKIPIF--
4-
<?php if( substr(PHP_OS, 0, 3) == "WIN" ) {die('skip not valid on Windows');} ?>
4+
<?php if( substr(PHP_OS, 0, 3) == "WIN" ) die('skip not valid directory on Windows'); ?>
55
--FILE--
66
<?php
77
$path = __DIR__;
@@ -19,10 +19,16 @@ var_dump(glob("$path/directly_not_exists"));
1919
var_dump($open_basedir == ini_get('open_basedir'));
2020
?>
2121
--EXPECT--
22-
bool(false)
23-
bool(false)
24-
bool(false)
25-
bool(false)
26-
bool(false)
27-
bool(false)
22+
array(0) {
23+
}
24+
array(0) {
25+
}
26+
array(0) {
27+
}
28+
array(0) {
29+
}
30+
array(0) {
31+
}
32+
array(0) {
33+
}
2834
bool(true)

‎ext/standard/tests/file/glob_variation6.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Test glob() function: ensure no platform difference, variation 4
33
--SKIPIF--
4-
<?php if( substr(PHP_OS, 0, 3) != "WIN" ) {die('skip only valid on Windows');} ?>
4+
<?php if( substr(PHP_OS, 0, 3) != "WIN" ) die('skip only valid directory on Windows'); ?>
55
--FILE--
66
<?php
77
$path = __DIR__;

0 commit comments

Comments
 (0)