From: Ahmed Abdou Date: Tue, 29 Jan 2019 07:59:45 +0000 (+0100) Subject: Fix bug #51068 (glob:// do not support current path relative) X-Git-Tag: php-7.2.16RC1~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec28d4c247ef3c7ab9af41ff6e26b802694492b2;p=php Fix bug #51068 (glob:// do not support current path relative) Fix DirectoryIterator glob://* current path relative queries --- diff --git a/NEWS b/NEWS index f823f484b9..fa5200ce84 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ PHP NEWS . Support Oracle Database tracing attributes ACTION, MODULE, CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter) +- SPL: + . Fixed bug #51068 (DirectoryIterator glob:// don't support current path + relative queries). (Ahmed Abdou) + - Standard: . Fixed bug #77552 (Unintialized php_stream_statbuf in stat functions). (John Stevenson) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index f411fca539..bc05044bc7 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -212,12 +212,21 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in } break; case SPL_FS_DIR: - if (intern->file_name) { - efree(intern->file_name); + { + size_t path_len = 0; + char *path = spl_filesystem_object_get_path(intern, &path_len); + if (intern->file_name) { + efree(intern->file_name); + } + /* if there is parent path, ammend it, otherwise just use the given path as is */ + if (path_len == 0) { + intern->file_name_len = spprintf( + &intern->file_name, 0, "%s", intern->u.dir.entry.d_name); + } else { + intern->file_name_len = spprintf( + &intern->file_name, 0, "%s%c%s", path, slash, intern->u.dir.entry.d_name); + } } - intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s", - spl_filesystem_object_get_path(intern, NULL), - slash, intern->u.dir.entry.d_name); break; } } /* }}} */ diff --git a/ext/spl/tests/bug51068.phpt b/ext/spl/tests/bug51068.phpt new file mode 100644 index 0000000000..0263536cc3 --- /dev/null +++ b/ext/spl/tests/bug51068.phpt @@ -0,0 +1,36 @@ +--TEST-- +SPL: glob wrapper interactions with DirectoryIterator +--FILE-- +getFilename()); + var_dump($f->getSize()); +} +$iter = new DirectoryIterator('glob://bug.51068.dir/*.51068'); +foreach ($iter as $f) { + var_dump($f->getFilename()); + var_dump($f->getSize()); +} +$iter = new DirectoryIterator('glob://bug.51068.dir'); +foreach ($iter as $f) { + var_dump($f->getFilename()); + var_dump($f->getSize() >= 0); +} +?> +--CLEAN-- + +--EXPECT-- +string(9) "bug.51068" +int(0) +string(14) "lvl2.bug.51068" +int(0) +string(13) "bug.51068.dir" +bool(true) diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 903119705b..b10318fef2 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -128,7 +128,7 @@ static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int ge if (pglob->path) { efree(pglob->path); } - if (path != gpath) { + if ((path - gpath) > 1) { path--; } pglob->path_len = path - gpath;