Skip to content

Commit ec28d4c

Browse files
Ahmed Abdounikic
Ahmed Abdou
authored andcommitted
Fix bug #51068 (glob:// do not support current path relative)
Fix DirectoryIterator glob://* current path relative queries
1 parent fe4d724 commit ec28d4c

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Support Oracle Database tracing attributes ACTION, MODULE,
1111
CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter)
1212

13+
- SPL:
14+
. Fixed bug #51068 (DirectoryIterator glob:// don't support current path
15+
relative queries). (Ahmed Abdou)
16+
1317
- Standard:
1418
. Fixed bug #77552 (Unintialized php_stream_statbuf in stat functions).
1519
(John Stevenson)

ext/spl/spl_directory.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,21 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in
212212
}
213213
break;
214214
case SPL_FS_DIR:
215-
if (intern->file_name) {
216-
efree(intern->file_name);
215+
{
216+
size_t path_len = 0;
217+
char *path = spl_filesystem_object_get_path(intern, &path_len);
218+
if (intern->file_name) {
219+
efree(intern->file_name);
220+
}
221+
/* if there is parent path, ammend it, otherwise just use the given path as is */
222+
if (path_len == 0) {
223+
intern->file_name_len = spprintf(
224+
&intern->file_name, 0, "%s", intern->u.dir.entry.d_name);
225+
} else {
226+
intern->file_name_len = spprintf(
227+
&intern->file_name, 0, "%s%c%s", path, slash, intern->u.dir.entry.d_name);
228+
}
217229
}
218-
intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s",
219-
spl_filesystem_object_get_path(intern, NULL),
220-
slash, intern->u.dir.entry.d_name);
221230
break;
222231
}
223232
} /* }}} */

ext/spl/tests/bug51068.phpt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
SPL: glob wrapper interactions with DirectoryIterator
3+
--FILE--
4+
<?php
5+
touch('bug.51068');
6+
mkdir('bug.51068.dir');
7+
touch('bug.51068.dir/lvl2.bug.51068');
8+
$iter = new DirectoryIterator('glob://*.51068');
9+
foreach ($iter as $f) {
10+
var_dump($f->getFilename());
11+
var_dump($f->getSize());
12+
}
13+
$iter = new DirectoryIterator('glob://bug.51068.dir/*.51068');
14+
foreach ($iter as $f) {
15+
var_dump($f->getFilename());
16+
var_dump($f->getSize());
17+
}
18+
$iter = new DirectoryIterator('glob://bug.51068.dir');
19+
foreach ($iter as $f) {
20+
var_dump($f->getFilename());
21+
var_dump($f->getSize() >= 0);
22+
}
23+
?>
24+
--CLEAN--
25+
<?php
26+
unlink('bug.51068');
27+
unlink('bug.51068.dir/lvl2.bug.51068');
28+
rmdir('bug.51068.dir');
29+
?>
30+
--EXPECT--
31+
string(9) "bug.51068"
32+
int(0)
33+
string(14) "lvl2.bug.51068"
34+
int(0)
35+
string(13) "bug.51068.dir"
36+
bool(true)

main/streams/glob_wrapper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int ge
128128
if (pglob->path) {
129129
efree(pglob->path);
130130
}
131-
if (path != gpath) {
131+
if ((path - gpath) > 1) {
132132
path--;
133133
}
134134
pglob->path_len = path - gpath;

0 commit comments

Comments
 (0)