]> granicus.if.org Git - php/commitdiff
- MFH: Fix Bug #42364 Crash when using getRealPath with DirectoryIterator
authorJohannes Schlüter <johannes@php.net>
Tue, 21 Aug 2007 22:45:53 +0000 (22:45 +0000)
committerJohannes Schlüter <johannes@php.net>
Tue, 21 Aug 2007 22:45:53 +0000 (22:45 +0000)
NEWS
ext/spl/spl_directory.c
ext/spl/tests/bug42364.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7395da7159e516c06a2d38f6576da74b9b875d57..32c11d31e9a23b0e8538a279fb1126570883b433 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP                                                                        NEWS
 16 Aug 2007, PHP 5.2.4RC2
 - Fixed oci8 and PDO_OCI extensions to allow configuring with Oracle 11g client
   libraries. (Chris Jones)
+- Fixed Bug #42364 (Crash when using getRealPath with DirectoryIterator).
+  (Johannes)
 - Fixed bug #42292 ($PHP_CONFIG not set for phpized builds). (Jani)
 - Fixed bug #42261 (header wrong for date field). (roberto at spadim dot com
   dot br, Ilia)
index b9fc22dfdd7b066ecad2863e1420873d07a4ccc7..6529bbc1d92e354292786723eb649ff59ac23bf1 100755 (executable)
@@ -858,7 +858,11 @@ SPL_METHOD(SplFileInfo, getRealPath)
 
        php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC);
 
-       if (VCWD_REALPATH(intern->file_name, buff)) {
+       if (intern->type == SPL_FS_DIR && !intern->file_name && intern->u.dir.entry.d_name[0]) {
+               spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+       }
+
+       if (intern->file_name_len && VCWD_REALPATH(intern->file_name, buff)) {
 #ifdef ZTS
                if (VCWD_ACCESS(buff, F_OK)) {
                        RETVAL_FALSE;
diff --git a/ext/spl/tests/bug42364.phpt b/ext/spl/tests/bug42364.phpt
new file mode 100644 (file)
index 0000000..b218be3
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #42364 (Crash when using getRealPath with DirectoryIterator)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+$it = new DirectoryIterator(dirname(__FILE__));
+
+foreach ($it as $e) {
+    if (gettype($e->getRealPath()) != "string") {
+        echo $e->getFilename(), " is a ", gettype($e->getRealPath()), "\n";
+    }
+}
+
+echo "===DONE==="
+?>
+--EXPECT--
+===DONE===