From 4ccf0b846e93e927c440af28cddec4b9921c3adb Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sun, 11 May 2008 21:30:05 +0000 Subject: [PATCH] slightly increase efficiency of function interception, and ensure that nothing fails even if the archive is unlinked mid-process --- ext/phar/func_interceptors.c | 15 +++++++++++ ext/phar/tests/phar_gobyebye.phpt | 44 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ext/phar/tests/phar_gobyebye.phpt diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index 40a32fe59a..b92d61a422 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -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 index 0000000000..d55bef0c30 --- /dev/null +++ b/ext/phar/tests/phar_gobyebye.phpt @@ -0,0 +1,44 @@ +--TEST-- +Phar: test edge cases of intercepted functions when the underlying phar archive has been unlinkArchive()d +--SKIPIF-- + +--INI-- +phar.readonly=0 +--FILE-- + +'); +include $pname . '/foo/hi'; +?> +===DONE=== +--CLEAN-- + + +--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 -- 2.50.1