From a256e06404e957dd6e8e7aac9dc245be36aa7d13 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 14 Aug 2008 13:02:13 +0000 Subject: [PATCH] Fixed bug #45613 Segfault when using is_file() on Apache-2.2.8 --- ext/phar/func_interceptors.c | 80 ++++++++++++++++++++++++++++++++++++ ext/phar/func_interceptors.h | 2 + ext/phar/phar.c | 72 +++++++++++++++++--------------- 3 files changed, 122 insertions(+), 32 deletions(-) diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index 93112e0ea9..4daa1c982e 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -1130,6 +1130,85 @@ void phar_intercept_functions_shutdown(TSRMLS_D) } /* }}} */ +static struct _phar_orig_functions { + void (*orig_fopen)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_file_get_contents)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_is_file)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_is_link)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_is_dir)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_opendir)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_file_exists)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_fileperms)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_fileinode)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_filesize)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_fileowner)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_filegroup)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_fileatime)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_filemtime)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_filectime)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_filetype)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_is_writable)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_is_readable)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_is_executable)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_lstat)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_readfile)(INTERNAL_FUNCTION_PARAMETERS); + void (*orig_stat)(INTERNAL_FUNCTION_PARAMETERS); +} phar_orig_functions = {NULL}; + +void phar_save_orig_functions(TSRMLS_D) /* {{{ */ +{ + phar_orig_functions.orig_fopen = PHAR_G(orig_fopen); + phar_orig_functions.orig_file_get_contents = PHAR_G(orig_file_get_contents); + phar_orig_functions.orig_is_file = PHAR_G(orig_is_file); + phar_orig_functions.orig_is_link = PHAR_G(orig_is_link); + phar_orig_functions.orig_is_dir = PHAR_G(orig_is_dir); + phar_orig_functions.orig_opendir = PHAR_G(orig_opendir); + phar_orig_functions.orig_file_exists = PHAR_G(orig_file_exists); + phar_orig_functions.orig_fileperms = PHAR_G(orig_fileperms); + phar_orig_functions.orig_fileinode = PHAR_G(orig_fileinode); + phar_orig_functions.orig_filesize = PHAR_G(orig_filesize); + phar_orig_functions.orig_fileowner = PHAR_G(orig_fileowner); + phar_orig_functions.orig_filegroup = PHAR_G(orig_filegroup); + phar_orig_functions.orig_fileatime = PHAR_G(orig_fileatime); + phar_orig_functions.orig_filemtime = PHAR_G(orig_filemtime); + phar_orig_functions.orig_filectime = PHAR_G(orig_filectime); + phar_orig_functions.orig_filetype = PHAR_G(orig_filetype); + phar_orig_functions.orig_is_writable = PHAR_G(orig_is_writable); + phar_orig_functions.orig_is_readable = PHAR_G(orig_is_readable); + phar_orig_functions.orig_is_executable = PHAR_G(orig_is_executable); + phar_orig_functions.orig_lstat = PHAR_G(orig_lstat); + phar_orig_functions.orig_readfile = PHAR_G(orig_readfile); + phar_orig_functions.orig_stat = PHAR_G(orig_stat); +} +/* }}} */ + +void phar_restore_orig_functions(TSRMLS_D) /* {{{ */ +{ + PHAR_G(orig_fopen) = phar_orig_functions.orig_fopen; + PHAR_G(orig_file_get_contents) = phar_orig_functions.orig_file_get_contents; + PHAR_G(orig_is_file) = phar_orig_functions.orig_is_file; + PHAR_G(orig_is_link) = phar_orig_functions.orig_is_link; + PHAR_G(orig_is_dir) = phar_orig_functions.orig_is_dir; + PHAR_G(orig_opendir) = phar_orig_functions.orig_opendir; + PHAR_G(orig_file_exists) = phar_orig_functions.orig_file_exists; + PHAR_G(orig_fileperms) = phar_orig_functions.orig_fileperms; + PHAR_G(orig_fileinode) = phar_orig_functions.orig_fileinode; + PHAR_G(orig_filesize) = phar_orig_functions.orig_filesize; + PHAR_G(orig_fileowner) = phar_orig_functions.orig_fileowner; + PHAR_G(orig_filegroup) = phar_orig_functions.orig_filegroup; + PHAR_G(orig_fileatime) = phar_orig_functions.orig_fileatime; + PHAR_G(orig_filemtime) = phar_orig_functions.orig_filemtime; + PHAR_G(orig_filectime) = phar_orig_functions.orig_filectime; + PHAR_G(orig_filetype) = phar_orig_functions.orig_filetype; + PHAR_G(orig_is_writable) = phar_orig_functions.orig_is_writable; + PHAR_G(orig_is_readable) = phar_orig_functions.orig_is_readable; + PHAR_G(orig_is_executable) = phar_orig_functions.orig_is_executable; + PHAR_G(orig_lstat) = phar_orig_functions.orig_lstat; + PHAR_G(orig_readfile) = phar_orig_functions.orig_readfile; + PHAR_G(orig_stat) = phar_orig_functions.orig_stat; +} +/* }}} */ + /* * Local variables: * tab-width: 4 @@ -1138,3 +1217,4 @@ void phar_intercept_functions_shutdown(TSRMLS_D) * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ + diff --git a/ext/phar/func_interceptors.h b/ext/phar/func_interceptors.h index d67d5f6380..e099d87b72 100644 --- a/ext/phar/func_interceptors.h +++ b/ext/phar/func_interceptors.h @@ -24,6 +24,8 @@ 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); +void phar_save_orig_functions(TSRMLS_D); +void phar_restore_orig_functions(TSRMLS_D); END_EXTERN_C() /* diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 9cb0b74916..36ec247b17 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -3367,15 +3367,6 @@ function_entry phar_functions[] = { }; /* }}}*/ -/* {{{ php_phar_init_globals - */ -static void php_phar_init_globals_module(zend_phar_globals *phar_globals) -{ - memset(phar_globals, 0, sizeof(zend_phar_globals)); - phar_globals->readonly = 1; -} -/* }}} */ - static size_t phar_zend_stream_reader(void *handle, char *buf, size_t len TSRMLS_DC) /* {{{ */ { return php_stream_read(phar_get_pharfp((phar_archive_data*)handle TSRMLS_CC), buf, len); @@ -3540,35 +3531,20 @@ skip_phar: typedef zend_op_array* (zend_compile_t)(zend_file_handle*, int TSRMLS_DC); typedef zend_compile_t* (compile_hook)(zend_compile_t *ptr); -PHP_MINIT_FUNCTION(phar) /* {{{ */ +PHP_GINIT_FUNCTION(phar) /* {{{ */ { phar_mime_type mime; - ZEND_INIT_MODULE_GLOBALS(phar, php_phar_init_globals_module, NULL); - REGISTER_INI_ENTRIES(); - - phar_orig_compile_file = zend_compile_file; - zend_compile_file = phar_compile_file; - -#if PHP_VERSION_ID >= 50300 - phar_save_resolve_path = zend_resolve_path; - zend_resolve_path = phar_resolve_path; -#else - phar_orig_zend_open = zend_stream_open_function; - zend_stream_open_function = phar_zend_open; -#endif - - phar_object_init(TSRMLS_C); - - phar_intercept_functions_init(TSRMLS_C); + memset(phar_globals, 0, sizeof(zend_phar_globals)); + phar_globals->readonly = 1; - zend_hash_init(&PHAR_G(mime_types), 0, NULL, NULL, 1); + zend_hash_init(&phar_globals->mime_types, 0, NULL, NULL, 1); #define PHAR_SET_MIME(mimetype, ret, fileext) \ mime.mime = mimetype; \ mime.len = sizeof((mimetype))+1; \ mime.type = ret; \ - zend_hash_add(&PHAR_G(mime_types), fileext, sizeof(fileext)-1, (void *)&mime, sizeof(phar_mime_type), NULL); \ + zend_hash_add(&phar_globals->mime_types, fileext, sizeof(fileext)-1, (void *)&mime, sizeof(phar_mime_type), NULL); \ PHAR_SET_MIME("text/html", PHAR_MIME_PHPS, "phps") PHAR_SET_MIME("text/plain", PHAR_MIME_OTHER, "c") @@ -3611,6 +3587,36 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */ PHAR_SET_MIME("image/xbm", PHAR_MIME_OTHER, "xbm") PHAR_SET_MIME("text/xml", PHAR_MIME_OTHER, "xml") + phar_restore_orig_functions(TSRMLS_C); +} +/* }}} */ + +PHP_GSHUTDOWN_FUNCTION(phar) /* {{{ */ +{ + zend_hash_destroy(&phar_globals->mime_types); +} +/* }}} */ + +PHP_MINIT_FUNCTION(phar) /* {{{ */ +{ + REGISTER_INI_ENTRIES(); + + phar_orig_compile_file = zend_compile_file; + zend_compile_file = phar_compile_file; + +#if PHP_VERSION_ID >= 50300 + phar_save_resolve_path = zend_resolve_path; + zend_resolve_path = phar_resolve_path; +#else + phar_orig_zend_open = zend_stream_open_function; + zend_stream_open_function = phar_zend_open; +#endif + + phar_object_init(TSRMLS_C); + + phar_intercept_functions_init(TSRMLS_C); + phar_save_orig_functions(TSRMLS_C); + return php_register_url_stream_wrapper("phar", &php_stream_phar_wrapper TSRMLS_CC); } /* }}} */ @@ -3619,8 +3625,6 @@ PHP_MSHUTDOWN_FUNCTION(phar) /* {{{ */ { php_unregister_url_stream_wrapper("phar" TSRMLS_CC); - zend_hash_destroy(&PHAR_G(mime_types)); - phar_intercept_functions_shutdown(TSRMLS_C); if (zend_compile_file == phar_compile_file) { @@ -3793,7 +3797,11 @@ zend_module_entry phar_module_entry = { PHP_RSHUTDOWN(phar), PHP_MINFO(phar), PHP_PHAR_VERSION, - STANDARD_MODULE_PROPERTIES + PHP_MODULE_GLOBALS(phar), /* globals descriptor */ + PHP_GINIT(phar), /* globals ctor */ + PHP_GSHUTDOWN(phar), /* globals dtor */ + NULL, /* post deactivate */ + STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ -- 2.50.1