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

index db8cf2816aa59b1d2739175900808f0ef6e57c77..53d3e88340e71a1cfb64daa2f14640c57a45b0e3 100755 (executable)
@@ -1020,13 +1020,17 @@ SPL_METHOD(SplFileInfo, getRealPath)
 
        php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC);
 
+       if (intern->type == SPL_FS_DIR && !intern->file_name.v && intern->u.dir.entry.d_name[0]) {
+               spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+       }
+
        if (intern->file_name_type == IS_UNICODE) {
                php_stream_path_encode(NULL, &filename, &filename_len, intern->file_name.u, intern->file_name_len, REPORT_ERRORS, FG(default_context));
        } else {
                filename = intern->file_name.s;
        }
 
-       if (VCWD_REALPATH(filename, buff)) {
+       if (filename && VCWD_REALPATH(filename, buff)) {
 #ifdef ZTS
                if (VCWD_ACCESS(buff, F_OK)) {
                        RETVAL_FALSE;
@@ -1044,6 +1048,11 @@ SPL_METHOD(SplFileInfo, getRealPath)
        } else {
                RETVAL_FALSE;
        }
+
+       if (intern->file_name_type == IS_UNICODE && filename) {
+               efree(filename);
+       }
+
        php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 }
 /* }}} */
diff --git a/ext/spl/tests/bug42364.phpt b/ext/spl/tests/bug42364.phpt
new file mode 100644 (file)
index 0000000..3ca083e
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Bug #42364 (Crash when using getRealPath with DirectoryIterator)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+$it = new DirectoryIterator(dirname(__FILE__));
+
+$count = 0;
+
+foreach ($it as $e) {
+    $count++;
+    $type = gettype($e->getRealPath());
+    if ($type != "string" && $type != "unicode") {
+        echo $e->getFilename(), " is a ", gettype($e->getRealPath()), "\n";
+    }
+}
+
+if ($count > 0) {
+    echo "Found $count entries!\n";
+}
+echo "===DONE==="
+?>
+--EXPECTF--
+Found %i entries!
+===DONE===