Skip to content

Commit dbac5a5

Browse files
author
cataphract
committed
- Fixed bug #54291 (Crash iterating DirectoryIterator for dir name starting
with \0). git-svn-id: http://svn.php.net/repository/php/php-src/php/php-src/trunk@309456 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent a443170 commit dbac5a5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ext/spl/spl_directory.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,12 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TS
232232
intern->u.dir.index = 0;
233233

234234
if (EG(exception) || intern->u.dir.dirp == NULL) {
235-
/* throw exception: should've been already happened */
236235
intern->u.dir.entry.d_name[0] = '\0';
236+
if (!EG(exception)) {
237+
/* open failed w/out notice (turned to exception due to EH_THROW) */
238+
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0
239+
TSRMLS_CC, "Failed to open directory \"%s\"", path);
240+
}
237241
} else {
238242
do {
239243
spl_filesystem_dir_read(intern TSRMLS_CC);

ext/spl/tests/bug54291.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #54291 (Crash iterating DirectoryIterator for dir name starting with \0)
3+
--FILE--
4+
<?php
5+
$dir = new DirectoryIterator("\x00/abc");
6+
$dir->isFile();
7+
--EXPECTF--
8+
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Failed to open directory ""' in %s:%d
9+
Stack trace:
10+
#0 %s(%d): DirectoryIterator->__construct('?/abc')
11+
#1 {main}
12+
thrown in %s on line %d
13+

0 commit comments

Comments
 (0)