From c111d1cd701d2720fdf2707640e70cc9ec5cf76e Mon Sep 17 00:00:00 2001 From: Julien Pauli Date: Fri, 20 Feb 2015 15:09:35 +0100 Subject: [PATCH] fix #68557 --- ext/spl/spl_directory.c | 11 +++++++---- ext/spl/tests/bug68557.phpt | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 ext/spl/tests/bug68557.phpt diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 7fc65cc791..34f0415b53 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -202,18 +202,21 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in { char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH; - if (!intern->file_name) { - switch (intern->type) { + switch (intern->type) { case SPL_FS_INFO: case SPL_FS_FILE: - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized"); + if (!intern->file_name) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized"); + } break; case SPL_FS_DIR: + if (intern->file_name) { + efree(intern->file_name); + } intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s", spl_filesystem_object_get_path(intern, NULL TSRMLS_CC), slash, intern->u.dir.entry.d_name); break; - } } } /* }}} */ diff --git a/ext/spl/tests/bug68557.phpt b/ext/spl/tests/bug68557.phpt new file mode 100644 index 0000000000..bcf66c9d24 --- /dev/null +++ b/ext/spl/tests/bug68557.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #68557 (SplFileInfo::getPathname() may be broken) +--FILE-- +seek(0); +var_dump($d->current()->getPathname()); + +$d->seek(1); +var_dump($d->current()->getPathname()); + +$d->seek(0); +var_dump($d->current()->getPathname()); + +$d->seek(1); +var_dump($d->current()->getPathname()); + +$d->seek(2); +var_dump($d->current()->getPathname()); +?> +--CLEAN-- + +--EXPECTF-- +string(%d) "%s/tmp/b" +string(%d) "%s/tmp/a" +string(%d) "%s/tmp/b" +string(%d) "%s/tmp/a" +string(%d) "%s/tmp/.." \ No newline at end of file -- 2.40.0