dmitry Thu Jul 10 11:36:50 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/phar func_interceptors.c func_interceptors.h phar.c phar_internal.h Log: Extensions MUST NOT manipulate with internal functions from EG(function_table) in run-time. It may cause problems with opcode caches and in multi-threaded environment. Now the same functions are overriden at MINIT and call original functions or PHAR ones dependent on flag setting.
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/func_interceptors.c?r1=1.20.2.7&r2=1.20.2.8&diff_format=u Index: php-src/ext/phar/func_interceptors.c diff -u php-src/ext/phar/func_interceptors.c:1.20.2.7 php-src/ext/phar/func_interceptors.c:1.20.2.8 --- php-src/ext/phar/func_interceptors.c:1.20.2.7 Sat Jun 21 20:47:35 2008 +++ php-src/ext/phar/func_interceptors.c Thu Jul 10 11:36:50 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: func_interceptors.c,v 1.20.2.7 2008/06/21 20:47:35 sfox Exp $ */ +/* $Id: func_interceptors.c,v 1.20.2.8 2008/07/10 11:36:50 dmitry Exp $ */ #include "phar_internal.h" @@ -29,6 +29,10 @@ int filename_len; zval *zcontext = NULL; + if (!PHAR_G(intercepted)) { + goto skip_phar; + } + if ((PHAR_GLOBALS->phar_fname_map.arBuckets && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) && !cached_phars.arBuckets) { goto skip_phar; @@ -98,6 +102,10 @@ long maxlen = PHP_STREAM_COPY_ALL; zval *zcontext = NULL; + if (!PHAR_G(intercepted)) { + goto skip_phar; + } + if ((PHAR_GLOBALS->phar_fname_map.arBuckets && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) && !cached_phars.arBuckets) { goto skip_phar; @@ -224,6 +232,10 @@ zval *zcontext = NULL; php_stream *stream; + if (!PHAR_G(intercepted)) { + goto skip_phar; + } + if ((PHAR_GLOBALS->phar_fname_map.arBuckets && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) && !cached_phars.arBuckets) { goto skip_phar; @@ -315,6 +327,10 @@ zval *zcontext = NULL; php_stream *stream; + if (!PHAR_G(intercepted)) { + goto skip_phar; + } + if ((PHAR_GLOBALS->phar_fname_map.arBuckets && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) && !cached_phars.arBuckets) { /* no need to check, include_path not even specified in fopen/ no active phars */ @@ -792,14 +808,18 @@ #define PharFileFunction(fname, funcnum, orig) \ void fname(INTERNAL_FUNCTION_PARAMETERS) { \ - char *filename; \ - int filename_len; \ - \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { \ - return; \ + if (!PHAR_G(intercepted)) { \ + PHAR_G(orig)(INTERNAL_FUNCTION_PARAM_PASSTHRU); \ + } else { \ + char *filename; \ + int filename_len; \ + \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { \ + return; \ + } \ + \ + phar_file_stat(filename, (php_stat_len) filename_len, funcnum, PHAR_G(orig), INTERNAL_FUNCTION_PARAM_PASSTHRU); \ } \ - \ - phar_file_stat(filename, (php_stat_len) filename_len, funcnum, PHAR_G(orig), INTERNAL_FUNCTION_PARAM_PASSTHRU); \ } /* }}} */ @@ -878,6 +898,10 @@ char *filename; int filename_len; + if (!PHAR_G(intercepted)) { + goto skip_phar; + } + if ((PHAR_GLOBALS->phar_fname_map.arBuckets && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) && !cached_phars.arBuckets) { goto skip_phar; @@ -939,6 +963,10 @@ char *filename; int filename_len; + if (!PHAR_G(intercepted)) { + goto skip_phar; + } + if ((PHAR_GLOBALS->phar_fname_map.arBuckets && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) && !cached_phars.arBuckets) { goto skip_phar; @@ -1006,6 +1034,26 @@ /* }}} */ /* {{{ void phar_intercept_functions(TSRMLS_D) */ +void phar_intercept_functions(TSRMLS_D) +{ + zend_function *orig; + + if (!PHAR_G(request_init)) { + PHAR_G(cwd) = NULL; + PHAR_G(cwd_len) = 0; + } + PHAR_G(intercepted) = 1; +} +/* }}} */ + +/* {{{ void phar_release_functions(TSRMLS_D) */ +void phar_release_functions(TSRMLS_D) +{ + PHAR_G(intercepted) = 0; +} +/* }}} */ + +/* {{{ void phar_intercept_functions_init(TSRMLS_D) */ #define PHAR_INTERCEPT(func) \ PHAR_G(orig_##func) = NULL; \ if (SUCCESS == zend_hash_find(CG(function_table), #func, sizeof(#func), (void **)&orig)) { \ @@ -1013,17 +1061,10 @@ orig->internal_function.handler = phar_##func; \ } -void phar_intercept_functions(TSRMLS_D) +void phar_intercept_functions_init(TSRMLS_D) { zend_function *orig; - if (!PHAR_G(request_init)) { - PHAR_G(cwd) = NULL; - PHAR_G(cwd_len) = 0; - } else if (PHAR_G(orig_fopen)) { - /* don't double-intercept */ - return; - } PHAR_INTERCEPT(fopen); PHAR_INTERCEPT(file_get_contents); PHAR_INTERCEPT(is_file); @@ -1046,17 +1087,18 @@ PHAR_INTERCEPT(lstat); PHAR_INTERCEPT(stat); PHAR_INTERCEPT(readfile); + PHAR_G(intercepted) = 0; } /* }}} */ -/* {{{ void phar_release_functions(TSRMLS_D) */ +/* {{{ void phar_intercept_functions_shutdown(TSRMLS_D) */ #define PHAR_RELEASE(func) \ if (PHAR_G(orig_##func) && SUCCESS == zend_hash_find(CG(function_table), #func, sizeof(#func), (void **)&orig)) { \ orig->internal_function.handler = PHAR_G(orig_##func); \ } \ PHAR_G(orig_##func) = NULL; -void phar_release_functions(TSRMLS_D) +void phar_intercept_functions_shutdown(TSRMLS_D) { zend_function *orig; @@ -1081,6 +1123,7 @@ PHAR_RELEASE(lstat); PHAR_RELEASE(stat); PHAR_RELEASE(readfile); + PHAR_G(intercepted) = 0; } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/phar/func_interceptors.h?r1=1.1&r2=1.1.2.1&diff_format=u Index: php-src/ext/phar/func_interceptors.h diff -u php-src/ext/phar/func_interceptors.h:1.1 php-src/ext/phar/func_interceptors.h:1.1.2.1 --- php-src/ext/phar/func_interceptors.h:1.1 Fri Jan 11 07:30:02 2008 +++ php-src/ext/phar/func_interceptors.h Thu Jul 10 11:36:50 2008 @@ -17,11 +17,13 @@ +----------------------------------------------------------------------+ */ -/* $Id: func_interceptors.h,v 1.1 2008/01/11 07:30:02 cellog Exp $ */ +/* $Id: func_interceptors.h,v 1.1.2.1 2008/07/10 11:36:50 dmitry Exp $ */ BEGIN_EXTERN_C() void phar_intercept_functions(TSRMLS_D); void phar_release_functions(TSRMLS_D); +void phar_intercept_functions_init(TSRMLS_D); +void phar_intercept_functions_shutdown(TSRMLS_D); END_EXTERN_C() /* http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.370.2.31&r2=1.370.2.32&diff_format=u Index: php-src/ext/phar/phar.c diff -u php-src/ext/phar/phar.c:1.370.2.31 php-src/ext/phar/phar.c:1.370.2.32 --- php-src/ext/phar/phar.c:1.370.2.31 Wed Jul 9 14:15:41 2008 +++ php-src/ext/phar/phar.c Thu Jul 10 11:36:50 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar.c,v 1.370.2.31 2008/07/09 14:15:41 tony2001 Exp $ */ +/* $Id: phar.c,v 1.370.2.32 2008/07/10 11:36:50 dmitry Exp $ */ #define PHAR_MAIN 1 #include "phar_internal.h" @@ -3299,13 +3299,18 @@ phar_object_init(TSRMLS_C); + phar_intercept_functions_init(TSRMLS_C); + return php_register_url_stream_wrapper("phar", &php_stream_phar_wrapper TSRMLS_CC); } /* }}} */ PHP_MSHUTDOWN_FUNCTION(phar) /* {{{ */ { - return php_unregister_url_stream_wrapper("phar" TSRMLS_CC); + php_unregister_url_stream_wrapper("phar" TSRMLS_CC); + + phar_intercept_functions_shutdown(TSRMLS_C); + if (zend_compile_file == phar_compile_file) { zend_compile_file = phar_orig_compile_file; } @@ -3319,6 +3324,8 @@ zend_hash_destroy(&(cached_phars)); zend_hash_destroy(&(cached_alias)); } + + return SUCCESS; } /* }}} */ @@ -3353,9 +3360,7 @@ PHAR_G(cwd) = NULL; PHAR_G(cwd_len) = 0; PHAR_G(cwd_init) = 0; - if (!PHAR_G(orig_fopen)) { - phar_intercept_functions(TSRMLS_C); - } + phar_intercept_functions(TSRMLS_C); } } /* }}} */ @@ -3407,7 +3412,7 @@ php_info_print_table_header(2, "Phar: PHP Archive support", "enabled"); php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION); php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION); - php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.31 $"); + php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.32 $"); php_info_print_table_row(2, "Phar-based phar archives", "enabled"); php_info_print_table_row(2, "Tar-based phar archives", "enabled"); php_info_print_table_row(2, "ZIP-based phar archives", "enabled"); @@ -3451,6 +3456,7 @@ ZEND_MOD_OPTIONAL("bz2") ZEND_MOD_OPTIONAL("openssl") ZEND_MOD_OPTIONAL("zlib") + ZEND_MOD_OPTIONAL("standard") #if HAVE_SPL ZEND_MOD_REQUIRED("spl") #endif http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar_internal.h?r1=1.109.2.19&r2=1.109.2.20&diff_format=u Index: php-src/ext/phar/phar_internal.h diff -u php-src/ext/phar/phar_internal.h:1.109.2.19 php-src/ext/phar/phar_internal.h:1.109.2.20 --- php-src/ext/phar/phar_internal.h:1.109.2.19 Sat Jun 21 19:40:41 2008 +++ php-src/ext/phar/phar_internal.h Thu Jul 10 11:36:50 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_internal.h,v 1.109.2.19 2008/06/21 19:40:41 sfox Exp $ */ +/* $Id: phar_internal.h,v 1.109.2.20 2008/07/10 11:36:50 dmitry Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -158,6 +158,7 @@ int has_bz2; zend_bool readonly_orig; zend_bool require_hash_orig; + zend_bool intercepted; int request_init; int require_hash; int request_done;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php