]> granicus.if.org Git - php/commitdiff
finish code coverage work (whew)
authorGreg Beaver <cellog@php.net>
Sat, 26 Apr 2008 05:28:56 +0000 (05:28 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 26 Apr 2008 05:28:56 +0000 (05:28 +0000)
ext/phar/tests/mounteddir.phpt
ext/phar/tests/zf_test.phpt
ext/phar/util.c

index eee69da9592fa6d6ffbcc7e9dc81006b4174bc02..c438eefb1d40bfa219a75e69835970ec1d991ef6 100644 (file)
@@ -12,15 +12,20 @@ $pname = 'phar://' . $fname;
 $a = new Phar($fname);
 $a['index.php'] = '<?php
 Phar::mount("testit", dirname(Phar::running(0)) . "/testit");
+echo file_get_contents(Phar::running(1) . "/testit/extfile.php"), "\n";
+echo file_get_contents(Phar::running(1) . "/testit/directory"), "\n";
+echo file_get_contents(Phar::running(1) . "/testit/existing.txt"), "\n";
 include "testit/extfile.php";
 include "testit/extfile2.php";
 ?>';
+$a['testit/existing.txt'] = 'oops';
 $a->setStub('<?php
 set_include_path("phar://" . __FILE__);
 include "index.php";
 __HALT_COMPILER();');
 unset($a);
 mkdir(dirname(__FILE__) . '/testit');
+mkdir(dirname(__FILE__) . '/testit/directory');
 file_put_contents(dirname(__FILE__) . '/testit/extfile.php', '<?php
 var_dump(__FILE__);
 ?>');
@@ -47,6 +52,26 @@ sort($out);
 foreach ($out as $b) {
        echo "$b\n";
 }
+try {
+Phar::mount($pname . '/testit', 'another\\..\\mistake');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+Phar::mount($pname . '/notfound', dirname(__FILE__) . '/this/does/not/exist');
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+Phar::mount($pname . '/testit', dirname(__FILE__));
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
+try {
+Phar::mount($pname . '/testit/extfile.php', dirname(__FILE__));
+} catch (Exception $e) {
+echo $e->getMessage(), "\n";
+}
 ?>
 ===DONE===
 --CLEAN--
@@ -54,17 +79,31 @@ foreach ($out as $b) {
 @unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
 @unlink(dirname(__FILE__) . '/testit/extfile.php');
 @unlink(dirname(__FILE__) . '/testit/extfile2.php');
+@rmdir(dirname(__FILE__) . '/testit/directory');
 @rmdir(dirname(__FILE__) . '/testit');
 
 ?>
 --EXPECTF--
 string(%d) "%sextfile.php"
+<?php
+var_dump(__FILE__);
+?>
+
+Warning: file_get_contents(phar://%stempmanifest1.phar.php/testit/directory): failed to open stream: phar error: path "testit/directory" is a directory in phar://%stempmanifest1.phar.php/index.php on line %d
+
+oops
 string(%d) "phar://%sextfile.php"
 string(%d) "phar://%sextfile2.php"
 .
 ..
+directory
 extfile.php
 extfile2.php
+phar://%stempmanifest1.phar.php/testit%cdirectory
 phar://%stempmanifest1.phar.php/testit%cextfile.php
 phar://%stempmanifest1.phar.php/testit%cextfile2.php
+Mounting of /testit to another\..\mistake within phar %stempmanifest1.phar.php failed
+Mounting of /notfound to %stests/this/does/not/exist within phar %stempmanifest1.phar.php failed
+Mounting of /testit to %stests within phar %stests/tempmanifest1.phar.php failed
+Mounting of /testit/extfile.php to %stests within phar %stests/tempmanifest1.phar.php failed
 ===DONE===
\ No newline at end of file
index 5a4a13c72ceffa6a5e9d797d7d31cde13d877c91..99e5c4f6e7e5694e1e1f0f2c3fd1cc67a6a798e4 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-test broken app
+Phar: test broken app
 --SKIPIF--
 <?php if (!extension_loaded("phar")) die("skip"); ?>
 --INI--
index f25a27c85a2478f9e27579c7d259f55ff72d90f6..26dd40926b1aca3aa38e6364c9ae090b8d3df670 100644 (file)
@@ -139,12 +139,14 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
 {
        phar_entry_info entry = {0};
        php_stream_statbuf ssb;
+       int is_phar;
        const char *err;
 
        if (phar_path_check(&path, &path_len, &err) > pcr_is_ok) {
                return FAILURE;
        }
 
+       is_phar = (filename_len > 7 && !memcmp(filename, "phar://", 7));
 
        entry.phar = phar;
        entry.filename = estrndup(path, path_len);
@@ -152,7 +154,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
        phar_unixify_path_separators(entry.filename, path_len);
 #endif
        entry.filename_len = path_len;
-       if (strstr(filename, "phar://")) {
+       if (is_phar) {
                entry.tmp = estrndup(filename, filename_len);
        } else {
                entry.tmp = expand_filepath(filename, NULL TSRMLS_CC);
@@ -161,7 +163,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
                }
        }
 #if PHP_MAJOR_VERSION < 6
-       if (PG(safe_mode) && !strstr(filename, "phar://") && (!php_checkuid(entry.tmp, NULL, CHECKUID_ALLOW_ONLY_FILE))) {
+       if (PG(safe_mode) && !is_phar && (!php_checkuid(entry.tmp, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
                efree(entry.tmp);
                efree(entry.filename);
                return FAILURE;
@@ -171,7 +173,7 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
        filename_len = strlen(entry.tmp);
        filename = entry.tmp;
        /* only check openbasedir for files, not for phar streams */
-       if (!strstr(filename, "phar://") && php_check_open_basedir(filename TSRMLS_CC)) {
+       if (!is_phar && php_check_open_basedir(filename TSRMLS_CC)) {
                efree(entry.tmp);
                efree(entry.filename);
                return FAILURE;
@@ -1178,7 +1180,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
                                        }
                                        return NULL;
                                }
-                               if (ssb.sb.st_mode & S_IFDIR && dir) {
+                               if ((ssb.sb.st_mode & S_IFDIR) == 0 && dir) {
                                        efree(test);
                                        /* user requested a directory, we must return one */
                                        if (error) {