Skip to content

Commit 32a728d

Browse files
committed
Fix #68825: Exception in DirectoryIterator::getLinkTarget()
intern->file_name may not have been properly set when DirectoryIterator::getLinkTarget() is called, so we make sure it is before using it.
1 parent 5fb01a3 commit 32a728d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ PHP NEWS
3838
(Kevin Abel)
3939

4040
- SPL:
41+
. Fixed bug #68825 (Exception in DirectoryIterator::getLinkTarget()). (cmb)
4142
. Fixed bug #68175 (RegexIterator pregFlags are NULL instead of 0). (Tim
4243
Siebels)
4344

ext/spl/spl_directory.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ SPL_METHOD(SplFileInfo, getLinkTarget)
12291229

12301230
zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
12311231

1232+
if (intern->file_name == NULL) {
1233+
spl_filesystem_object_get_file_name(intern);
1234+
}
12321235
#if defined(PHP_WIN32) || HAVE_SYMLINK
12331236
if (intern->file_name == NULL) {
12341237
php_error_docref(NULL, E_WARNING, "Empty filename");

ext/spl/tests/bug68825.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #68825 (Exception in DirectoryIterator::getLinkTarget())
3+
--FILE--
4+
<?php
5+
$dir = __DIR__ . '/bug68825';
6+
mkdir($dir);
7+
symlink(__FILE__, "$dir/foo");
8+
9+
$di = new \DirectoryIterator($dir);
10+
foreach ($di as $entry) {
11+
if ('foo' === $entry->getFilename()) {
12+
var_dump($entry->getLinkTarget());
13+
}
14+
}
15+
?>
16+
===DONE===
17+
--EXPECTF--
18+
string(%d) "%s%eext%espl%etests%ebug68825.php"
19+
===DONE===
20+
--CLEAN--
21+
<?php
22+
$dir = __DIR__ . '/bug68825';
23+
unlink("$dir/foo");
24+
rmdir($dir);
25+
?>

0 commit comments

Comments
 (0)