com php-src: fix #68557: ext/spl/spl_directory.c ext/spl/ tests/bug68557.phpt
| From: | JulienPauli | Date: | Fri, 20 Feb 2015 14:09:35 +0000 |
| Subject: | com php-src: fix #68557: ext/spl/spl_directory.c ext/spl/ tests/bug68557.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85027@lists.php.net to get a copy of this message | ||
Commit: c111d1cd701d2720fdf2707640e70cc9ec5cf76e
Author: Julien Pauli <jpauli@php.net> Fri, 20 Feb 2015 15:09:35 +0100
Parents: 9fb48edf3c32914330b7a5081a34b4328bf6da68
Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c111d1cd701d2720fdf2707640e70cc9ec5cf76e
Log:
fix #68557
Bugs:
https://bugs.php..net/68557
Changed paths:
M ext/spl/spl_directory.c
A ext/spl/tests/bug68557.phpt
Diff:
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 7fc65cc..34f0415 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 0000000..bcf66c9
--- /dev/null
+++ b/ext/spl/tests/bug68557.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Bug #68557 (SplFileInfo::getPathname() may be broken)
+--FILE--
+<?php
+mkdir(__DIR__ . DIRECTORY_SEPARATOR . 'tmp');
+touch(__DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'a');
+touch(__DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'b');
+
+$d = new DirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . 'tmp');
+
+$d->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--
+<?php
+unlink(__DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'a');
+unlink(__DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'b');
+rmdir(__DIR__ . DIRECTORY_SEPARATOR . 'tmp');
+?>
+--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