]> granicus.if.org Git - php/commitdiff
making progress (include magic works)
authorGreg Beaver <cellog@php.net>
Wed, 19 Dec 2007 03:17:05 +0000 (03:17 +0000)
committerGreg Beaver <cellog@php.net>
Wed, 19 Dec 2007 03:17:05 +0000 (03:17 +0000)
ext/phar/phar.c
ext/phar/tests/phar_magic.phpt

index 5bb738b3449bd25cf67f271a9f5d9ca421f07929..22ac0ecfae4e7e931de177193b98a86d0eb13b91 100644 (file)
@@ -3748,6 +3748,7 @@ static void php_phar_init_globals_module(zend_phar_globals *phar_globals)
 static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) /* {{{ */
 {
        zend_op_array *res;
+       char *s, *name = NULL;
        char *fname = NULL;
        int fname_len;
        zend_op_array *(*save)(zend_file_handle *file_handle, int type TSRMLS_DC);
@@ -3763,7 +3764,6 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type
                }
                fname_len = strlen(fname);
                if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len TSRMLS_CC)) {
-                       char *s, *name;
 
                        efree(entry);
                        entry = file_handle->filename;
@@ -3785,6 +3785,9 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type
        }
 skip_phar:
        res = zend_compile_file(file_handle, type TSRMLS_CC);
+       if (name) {
+               efree(name);
+       }
        zend_compile_file = save;
        return res;
 }
@@ -3902,11 +3905,11 @@ void phar_request_initialize(TSRMLS_D) /* {{{ */
                zend_hash_init(&(PHAR_GLOBALS->phar_alias_map), sizeof(phar_archive_data*), zend_get_hash_value, NULL, 0);
                zend_hash_init(&(PHAR_GLOBALS->phar_plain_map), sizeof(const char *),       zend_get_hash_value, NULL, 0);
                phar_split_extract_list(TSRMLS_C);
-               if (PHAR_G(orig_fopen) && SUCCESS == zend_hash_find(EG(function_table), "fopen", 5, (void **)&orig)) {
+               if (SUCCESS == zend_hash_find(CG(function_table), "fopen", 5, (void **)&orig)) {
                        PHAR_G(orig_fopen) = orig->internal_function.handler;
                        orig->internal_function.handler = phar_fopen;
                }
-               if (SUCCESS == zend_hash_find(EG(function_table), "getcwd", 5, (void **)&orig)) {
+               if (SUCCESS == zend_hash_find(CG(function_table), "getcwd", 5, (void **)&orig)) {
                        PHAR_G(orig_getcwd) = orig->internal_function.handler;
                        orig->internal_function.handler = phar_getcwd;
                }
index adb3ad5c90dd6061de400c236a0ea917e83028a9..a813560a9d299da5309c1c42d05a03f4b103fd93 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Phar::setStub()
+Phar: include/getcwd/fopen magic
 --SKIPIF--
 <?php if (!extension_loaded("phar")) print "skip"; ?>
 --INI--
@@ -9,7 +9,12 @@ phar.readonly=0
 <?php
 $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
 $p = new Phar($fname);
-$p['a'] = '<?php include "b.php";';
+$p['a'] = '<?php include "b/c.php";' . "\n";
+$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);echo getcwd() . "\n";';
+$p->setStub('<?php
+include "phar://" . __FILE__ . "/a";
+__HALT_COMPILER();');
+include $fname;
 ?>
 ===DONE===
 --CLEAN--
@@ -17,5 +22,8 @@ $p['a'] = '<?php include "b.php";';
 unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
 __HALT_COMPILER();
 ?>
---EXPECT--
+--EXPECTF--
+in b
+<?php include "b/c.php";
+phar://%s/b
 ===DONE===