]> granicus.if.org Git - php/commitdiff
add test for opendir, fix bugs found
authorGreg Beaver <cellog@php.net>
Sat, 12 Apr 2008 22:21:29 +0000 (22:21 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 12 Apr 2008 22:21:29 +0000 (22:21 +0000)
ext/phar/func_interceptors.c
ext/phar/tests/opendir.phpt [new file with mode: 0644]

index d12c49138203acf9d3254a7c74aaa4296f546ffe..c814545464c7108733f35a5a09cf0ca1f3cd02e1 100644 (file)
@@ -51,7 +51,7 @@ PHAR_FUNC(phar_opendir) /* {{{ */
                        char *name;
 
                        efree(entry);
-                       entry = filename;
+                       entry = estrndup(filename, filename_len);
                        /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
                        entry_len = filename_len;
                        if (strstr(entry, "://")) {
@@ -70,11 +70,9 @@ PHAR_FUNC(phar_opendir) /* {{{ */
                        stream = php_stream_opendir(name, REPORT_ERRORS, context);
                        efree(name);
                        if (!stream) {
-                               efree(entry);
                                goto skip_phar;
                        }
                        php_stream_to_zval(stream, return_value);
-                       efree(entry);
                        return;
                }
        }
diff --git a/ext/phar/tests/opendir.phpt b/ext/phar/tests/opendir.phpt
new file mode 100644 (file)
index 0000000..62dd9d6
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+Phar: test opendir() interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=1
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+$a = opendir("dir");
+while (false !== ($e = readdir($a))) {
+    echo $e;
+}
+?>';
+$a['dir/file1.txt'] = 'hi';
+$a['dir/file2.txt'] = 'hi2';
+$a['dir/file3.txt'] = 'hi3';
+$a->setStub('<?php
+Phar::interceptFileFuncs();
+set_include_path("phar://" . __FILE__);
+include "index.php";
+__HALT_COMPILER();');
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+file1.txtfile2.txtfile3.txt===DONE===
\ No newline at end of file