]> granicus.if.org Git - php/commitdiff
Fix #68825: Exception in DirectoryIterator::getLinkTarget()
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 19 Aug 2018 12:03:47 +0000 (14:03 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 22 Aug 2018 13:37:02 +0000 (15:37 +0200)
intern->file_name may not have been properly set when
DirectoryIterator::getLinkTarget() is called, so we make sure it is
before using it.

NEWS
ext/spl/spl_directory.c
ext/spl/tests/bug68825.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 78d9dba0b32bb2d2b68657eb1bd085b0f243309c..727508aac51533ec6c3048846e635622a9989947 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,7 @@ PHP                                                                        NEWS
     (Kevin Abel)
 
 - SPL:
+  . Fixed bug #68825 (Exception in DirectoryIterator::getLinkTarget()). (cmb)
   . Fixed bug #68175 (RegexIterator pregFlags are NULL instead of 0). (Tim
     Siebels)
 
index 4942799cf7885b74a3d31bfabbfb8944c7720add..fc4001ae1f8c09b1ab4f41bcceb868e1f930f383 100644 (file)
@@ -1229,6 +1229,9 @@ SPL_METHOD(SplFileInfo, getLinkTarget)
 
        zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
 
+       if (intern->file_name == NULL) {
+               spl_filesystem_object_get_file_name(intern);
+       }
 #if defined(PHP_WIN32) || HAVE_SYMLINK
        if (intern->file_name == NULL) {
                php_error_docref(NULL, E_WARNING, "Empty filename");
diff --git a/ext/spl/tests/bug68825.phpt b/ext/spl/tests/bug68825.phpt
new file mode 100644 (file)
index 0000000..b1ed5fb
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #68825 (Exception in DirectoryIterator::getLinkTarget())
+--FILE--
+<?php
+$dir = __DIR__ . '/bug68825';
+mkdir($dir);
+symlink(__FILE__, "$dir/foo");
+
+$di = new \DirectoryIterator($dir);
+foreach ($di as $entry) {
+    if ('foo' === $entry->getFilename()) {
+        var_dump($entry->getLinkTarget());
+    }
+}
+?>
+===DONE===
+--EXPECTF--
+string(%d) "%s%eext%espl%etests%ebug68825.php"
+===DONE===
+--CLEAN--
+<?php
+$dir = __DIR__ . '/bug68825';
+unlink("$dir/foo");
+rmdir($dir);
+?>