]> granicus.if.org Git - php/commitdiff
- Fixed bug #54291 (Crash iterating DirectoryIterator for dir name starting
authorGustavo André dos Santos Lopes <cataphract@php.net>
Sat, 19 Mar 2011 23:15:04 +0000 (23:15 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Sat, 19 Mar 2011 23:15:04 +0000 (23:15 +0000)
  with \0).

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

diff --git a/NEWS b/NEWS
index c9c621def9b6622bf5e5b5ce6b6f96fb9466a662..798e4be4a2998b0dcc98267b945a0ff22751c77c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,10 @@ PHP                                                                        NEWS
 - Sockets extension:
   . Fixed bug #51958 (socket_accept() fails on IPv6 server sockets). (Gustavo)
 
+- SPL extension:
+  . Fixed bug #54291 (Crash iterating DirectoryIterator for dir name starting
+    with \0). (Gustavo)
+
 17 Mar 2011, PHP 5.3.6
 - Upgraded bundled Sqlite3 to version 3.7.4. (Ilia)
 - Upgraded bundled PCRE to version 8.11. (Ilia)
index 421c9f1c851d137dccea0c5db0abc30d5628e691..83501aa7a870b3eb4e0b82f27048d7202eabeb10 100755 (executable)
@@ -233,8 +233,12 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TS
        intern->u.dir.index = 0;
 
        if (EG(exception) || intern->u.dir.dirp == NULL) {
-               /* throw exception: should've been already happened */
                intern->u.dir.entry.d_name[0] = '\0';
+               if (!EG(exception)) {
+                       /* open failed w/out notice (turned to exception due to EH_THROW) */
+                       zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0
+                               TSRMLS_CC, "Failed to open directory \"%s\"", path);
+               }
        } else {
                do {
                        spl_filesystem_dir_read(intern TSRMLS_CC);
diff --git a/ext/spl/tests/bug54291.phpt b/ext/spl/tests/bug54291.phpt
new file mode 100644 (file)
index 0000000..b8f596e
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #54291 (Crash iterating DirectoryIterator for dir name starting with \0)
+--FILE--
+<?php
+$dir = new DirectoryIterator("\x00/abc");
+$dir->isFile();
+--EXPECTF--
+Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Failed to open directory ""' in %s:%d
+Stack trace:
+#0 %s(%d): DirectoryIterator->__construct('?/abc')
+#1 {main}
+  thrown in %s on line %d
+