]> granicus.if.org Git - php/commitdiff
slightly increase efficiency of function interception, and ensure that nothing fails...
authorGreg Beaver <cellog@php.net>
Sun, 11 May 2008 21:30:05 +0000 (21:30 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 11 May 2008 21:30:05 +0000 (21:30 +0000)
ext/phar/func_interceptors.c
ext/phar/tests/phar_gobyebye.phpt [new file with mode: 0644]

index 40a32fe59ad51670c6e7830874f4a8b2d6ee765a..b92d61a4224bd874a6ca9463c45b4811eb4a58cc 100644 (file)
@@ -29,6 +29,9 @@ PHAR_FUNC(phar_opendir) /* {{{ */
        int filename_len;
        zval *zcontext = NULL;
 
+       if (!zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) {
+               goto skip_phar;
+       }
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &filename, &filename_len, &zcontext) == FAILURE) {
                return;
        }
@@ -94,6 +97,9 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */
        long maxlen = PHP_STREAM_COPY_ALL;
        zval *zcontext = NULL;
 
+       if (!zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) {
+               goto skip_phar;
+       }
        /* Parse arguments */
        if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) {
                return;
@@ -216,6 +222,9 @@ PHAR_FUNC(phar_readfile) /* {{{ */
        zval *zcontext = NULL;
        php_stream *stream;
 
+       if (!zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) {
+               goto skip_phar;
+       }
        if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) {
                goto skip_phar;
        }
@@ -858,6 +867,9 @@ PHAR_FUNC(phar_is_file) /* {{{ */
        char *filename;
        int filename_len;
 
+       if (!zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) {
+               goto skip_phar;
+       }
        if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
                goto skip_phar;
        }
@@ -915,6 +927,9 @@ PHAR_FUNC(phar_is_link) /* {{{ */
        char *filename;
        int filename_len;
 
+       if (!zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) {
+               goto skip_phar;
+       }
        if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
                goto skip_phar;
        }
diff --git a/ext/phar/tests/phar_gobyebye.phpt b/ext/phar/tests/phar_gobyebye.phpt
new file mode 100644 (file)
index 0000000..d55bef0
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+Phar: test edge cases of intercepted functions when the underlying phar archive has been unlinkArchive()d
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.php';
+$pname = 'phar://' . $fname;
+file_put_contents($fname2, '<?php Phar::unlinkArchive("' . addslashes($fname) . '");');
+file_put_contents($pname . '/foo/hi', '<?php
+include "' . addslashes($fname2) . '";
+readfile("foo/hi");
+fopen("foo/hi", "r");
+echo file_get_contents("foo/hi");
+var_dump(is_file("foo/hi"),is_link("foo/hi"),is_dir("foo/hi"),file_exists("foo/hi"),stat("foo/hi"));
+opendir("foo/hi");
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.php'); ?>
+--EXPECTF--
+Warning: readfile(foo/hi): failed to open stream: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+
+Warning: fopen(foo/hi): failed to open stream: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+
+Warning: file_get_contents(foo/hi): failed to open stream: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+
+Warning: stat(): stat failed for foo/hi in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: opendir(foo/hi): failed to open dir: No such file or directory in phar://%sphar_gobyebye.phar.php/foo/hi on line %d
+===DONE===
\ No newline at end of file