Skip to content

Commit

Permalink
Fix #68825: Exception in DirectoryIterator::getLinkTarget()
Browse files Browse the repository at this point in the history
intern->file_name may not have been properly set when
DirectoryIterator::getLinkTarget() is called, so we make sure it is
before using it.
  • Loading branch information
cmb69 committed Aug 22, 2018
1 parent 5fb01a3 commit 32a728d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
25 changes: 25 additions & 0 deletions ext/spl/tests/bug68825.phpt
Original file line number Diff line number Diff line change
@@ -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);
?>

0 comments on commit 32a728d

Please sign in to comment.