From f06e3ba5c1d7e02157acb77bdad3a0e7824da5f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Sat, 19 Mar 2011 23:15:04 +0000 Subject: [PATCH] - Fixed bug #54291 (Crash iterating DirectoryIterator for dir name starting with \0). --- NEWS | 4 ++++ ext/spl/spl_directory.c | 6 +++++- ext/spl/tests/bug54291.phpt | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/bug54291.phpt diff --git a/NEWS b/NEWS index c9c621def9..798e4be4a2 100644 --- 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) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 421c9f1c85..83501aa7a8 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -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 index 0000000000..b8f596e02c --- /dev/null +++ b/ext/spl/tests/bug54291.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #54291 (Crash iterating DirectoryIterator for dir name starting with \0) +--FILE-- +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 + -- 2.40.0