From 336004f4bc72fb5f1a4f8c992d90673960d74856 Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Sat, 21 Jul 2001 14:27:56 +0000 Subject: [PATCH] Improved bailout mechanism, supports nested bailouts a-la try..catch Note: You may *not* return directly from a catch block --- ext/standard/basic_functions.c | 15 +- main/main.c | 193 +++++++------ sapi/apache/mod_php4.c | 120 ++++---- sapi/apache/sapi_apache.c | 9 +- sapi/cgi/cgi_main.c | 510 ++++++++++++++++----------------- sapi/isapi/php4isapi.c | 172 +++++------ sapi/pi3web/pi3web_sapi.c | 110 +++---- sapi/servlet/servlet.c | 177 ++++++------ 8 files changed, 642 insertions(+), 664 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 6c94209ada..aaec3beb1e 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1889,21 +1889,12 @@ void php_call_shutdown_functions(void) BLS_FETCH(); ELS_FETCH(); - if (BG(user_shutdown_function_names)) { - jmp_buf orig_bailout; - - memcpy(&orig_bailout, &EG(bailout), sizeof(jmp_buf)); - if (setjmp(EG(bailout))!=0) { - /* one of the shutdown functions bailed out */ - memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf)); - return; - } - zend_hash_apply(BG(user_shutdown_function_names), - (apply_func_t)user_shutdown_function_call); + if (BG(user_shutdown_function_names)) zend_try { + zend_hash_apply(BG(user_shutdown_function_names), (apply_func_t)user_shutdown_function_call); memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf)); zend_hash_destroy(BG(user_shutdown_function_names)); efree(BG(user_shutdown_function_names)); - } + } zend_end_try(); } /* {{{ proto void register_shutdown_function(string function_name) diff --git a/main/main.c b/main/main.c index 3bc12ab314..737152d849 100644 --- a/main/main.c +++ b/main/main.c @@ -620,54 +620,56 @@ static int php_hash_environment(ELS_D SLS_DC PLS_DC); */ int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC) { + int retval = SUCCESS; + #if PHP_SIGCHILD signal(SIGCHLD,sigchld_handler); #endif - if (setjmp(EG(bailout))!=0) { - return FAILURE; - } - - PG(during_request_startup) = 1; - - php_output_activate(); + zend_try { + PG(during_request_startup) = 1; + + php_output_activate(); - /* initialize global variables */ - PG(modules_activated) = 0; - PG(header_is_being_sent) = 0; - PG(connection_status) = PHP_CONNECTION_NORMAL; - - zend_activate(CLS_C ELS_CC); - sapi_activate(SLS_C); + /* initialize global variables */ + PG(modules_activated) = 0; + PG(header_is_being_sent) = 0; + PG(connection_status) = PHP_CONNECTION_NORMAL; + + zend_activate(CLS_C ELS_CC); + sapi_activate(SLS_C); - zend_set_timeout(EG(timeout_seconds)); + zend_set_timeout(EG(timeout_seconds)); - if (PG(expose_php)) { - sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); - } + if (PG(expose_php)) { + sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1); + } - if (PG(output_handler) && PG(output_handler)[0]) { - zval *output_handler; - - ALLOC_INIT_ZVAL(output_handler); - Z_STRLEN_P(output_handler) = strlen(PG(output_handler)); /* this can be optimized */ - Z_STRVAL_P(output_handler) = estrndup(PG(output_handler), Z_STRLEN_P(output_handler)); - Z_TYPE_P(output_handler) = IS_STRING; - php_start_ob_buffer(output_handler, 0); - } else if (PG(output_buffering)) { - php_start_ob_buffer(NULL, 0); - } else if (PG(implicit_flush)) { - php_start_implicit_flush(); - } + if (PG(output_handler) && PG(output_handler)[0]) { + zval *output_handler; + + ALLOC_INIT_ZVAL(output_handler); + Z_STRLEN_P(output_handler) = strlen(PG(output_handler)); /* this can be optimized */ + Z_STRVAL_P(output_handler) = estrndup(PG(output_handler), Z_STRLEN_P(output_handler)); + Z_TYPE_P(output_handler) = IS_STRING; + php_start_ob_buffer(output_handler, 0); + } else if (PG(output_buffering)) { + php_start_ob_buffer(NULL, 0); + } else if (PG(implicit_flush)) { + php_start_implicit_flush(); + } - /* We turn this off in php_execute_script() */ - /* PG(during_request_startup) = 0; */ + /* We turn this off in php_execute_script() */ + /* PG(during_request_startup) = 0; */ - php_hash_environment(ELS_C SLS_CC PLS_CC); - zend_activate_modules(); - PG(modules_activated)=1; + php_hash_environment(ELS_C SLS_CC PLS_CC); + zend_activate_modules(); + PG(modules_activated)=1; + } zend_catch { + retval = FAILURE; + } zend_end_try(); - return SUCCESS; + return retval; } /* }}} */ @@ -692,17 +694,17 @@ void php_request_shutdown(void *dummy) php_output_set_status(0); - if (setjmp(EG(bailout))==0) { + zend_try { php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1)); - } + } zend_end_try(); - if (setjmp(EG(bailout))==0) { + zend_try { sapi_send_headers(); - } + } zend_end_try(); - if (PG(modules_activated) && setjmp(EG(bailout))==0) { + if (PG(modules_activated)) zend_try { php_call_shutdown_functions(); - } + } zend_end_try(); if (PG(modules_activated)) { zend_deactivate_modules(); @@ -710,17 +712,17 @@ void php_request_shutdown(void *dummy) zend_deactivate(CLS_C ELS_CC); - if (setjmp(EG(bailout))==0) { + zend_try { sapi_deactivate(SLS_C); - } + } zend_end_try(); - if (setjmp(EG(bailout))==0) { + zend_try { shutdown_memory_manager(CG(unclean_shutdown), 0); - } + } zend_end_try(); - if (setjmp(EG(bailout))==0) { + zend_try { zend_unset_timeout(); - } + } zend_end_try(); } /* }}} */ @@ -866,6 +868,7 @@ int php_module_startup(sapi_module_struct *sf) core_globals_id = ts_allocate_id(sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL); core_globals = ts_resource(core_globals_id); #endif + EG(bailout_set) = 0; EG(error_reporting) = E_ALL & ~E_NOTICE; PG(header_is_being_sent) = 0; @@ -1239,55 +1242,51 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_D SLS_FETCH(); EG(exit_status) = 0; - if (php_handle_special_queries(SLS_C PLS_CC)) + if (php_handle_special_queries(SLS_C PLS_CC)) { return 0; + } #define OLD_CWD_SIZE 4096 old_cwd = do_alloca(OLD_CWD_SIZE); old_cwd[0] = '\0'; - if (setjmp(EG(bailout))!=0) { - if (old_cwd[0] != '\0') - VCWD_CHDIR(old_cwd); - free_alloca(old_cwd); - return EG(exit_status); - } - + zend_try { #ifdef PHP_WIN32 - UpdateIniFromRegistry(primary_file->filename); + UpdateIniFromRegistry(primary_file->filename); #endif - PG(during_request_startup) = 0; + PG(during_request_startup) = 0; - if (primary_file->type == ZEND_HANDLE_FILENAME - && primary_file->filename) { - VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1); - VCWD_CHDIR_FILE(primary_file->filename); - } + if (primary_file->type == ZEND_HANDLE_FILENAME + && primary_file->filename) { + VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1); + VCWD_CHDIR_FILE(primary_file->filename); + } - if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { - prepend_file.filename = PG(auto_prepend_file); - prepend_file.opened_path = NULL; - prepend_file.free_filename = 0; - prepend_file.type = ZEND_HANDLE_FILENAME; - prepend_file_p = &prepend_file; - } else { - prepend_file_p = NULL; - } - if (PG(auto_append_file) && PG(auto_append_file)[0]) { - append_file.filename = PG(auto_append_file); - append_file.opened_path = NULL; - append_file.free_filename = 0; - append_file.type = ZEND_HANDLE_FILENAME; - append_file_p = &append_file; - } else { - append_file_p = NULL; - } - zend_execute_scripts(ZEND_REQUIRE CLS_CC ELS_CC, 3, prepend_file_p, primary_file, append_file_p); + if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { + prepend_file.filename = PG(auto_prepend_file); + prepend_file.opened_path = NULL; + prepend_file.free_filename = 0; + prepend_file.type = ZEND_HANDLE_FILENAME; + prepend_file_p = &prepend_file; + } else { + prepend_file_p = NULL; + } + if (PG(auto_append_file) && PG(auto_append_file)[0]) { + append_file.filename = PG(auto_append_file); + append_file.opened_path = NULL; + append_file.free_filename = 0; + append_file.type = ZEND_HANDLE_FILENAME; + append_file_p = &append_file; + } else { + append_file_p = NULL; + } + zend_execute_scripts(ZEND_REQUIRE CLS_CC ELS_CC, 3, prepend_file_p, primary_file, append_file_p); + } zend_end_try(); - if (old_cwd[0] != '\0') + if (old_cwd[0] != '\0') { VCWD_CHDIR(old_cwd); + } free_alloca(old_cwd); - return EG(exit_status); } /* }}} */ @@ -1345,20 +1344,20 @@ PHPAPI int php_lint_script(zend_file_handle *file CLS_DC ELS_DC PLS_DC) zend_op_array *op_array; SLS_FETCH(); - if (setjmp(EG(bailout))!=0) { - return FAILURE; - } + zend_try { + op_array = zend_compile_file(file, ZEND_INCLUDE CLS_CC); + zend_destroy_file_handle(file CLS_CC); - op_array = zend_compile_file(file, ZEND_INCLUDE CLS_CC); - zend_destroy_file_handle(file CLS_CC); + if (op_array) { + destroy_op_array(op_array); + efree(op_array); + return SUCCESS; + } else { + return FAILURE; + } + } zend_end_try(); - if (op_array) { - destroy_op_array(op_array); - efree(op_array); - return SUCCESS; - } else { - return FAILURE; - } + return FAILURE; } /* }}} */ diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c index db90946b53..53ddb92d87 100644 --- a/sapi/apache/mod_php4.c +++ b/sapi/apache/mod_php4.c @@ -506,83 +506,83 @@ static int send_php(request_rec *r, int display_source_mode, char *filename) return OK; } - if (setjmp(EG(bailout))!=0) { - return OK; - } - /* We don't accept OPTIONS requests, but take everything else */ - if (r->method_number == M_OPTIONS) { - r->allowed |= (1 << METHODS) - 1; - return DECLINED; - } + zend_try { + /* We don't accept OPTIONS requests, but take everything else */ + if (r->method_number == M_OPTIONS) { + r->allowed |= (1 << METHODS) - 1; + return DECLINED; + } - /* Make sure file exists */ - if (filename == NULL && r->finfo.st_mode == 0) { - return DECLINED; - } + /* Make sure file exists */ + if (filename == NULL && r->finfo.st_mode == 0) { + return DECLINED; + } - per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module); - if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf, (int (*)(void *)) php_apache_alter_ini_entries); - } + per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module); + if (per_dir_conf) { + zend_hash_apply((HashTable *) per_dir_conf, (int (*)(void *)) php_apache_alter_ini_entries); + } - /* If PHP parser engine has been turned off with an "engine off" - * directive, then decline to handle this request - */ - if (!AP(engine)) { - r->content_type = php_apache_get_default_mimetype(r SLS_CC); - r->allowed |= (1 << METHODS) - 1; - if (setjmp(EG(bailout))==0) { - zend_ini_deactivate(ELS_C); + /* If PHP parser engine has been turned off with an "engine off" + * directive, then decline to handle this request + */ + if (!AP(engine)) { + r->content_type = php_apache_get_default_mimetype(r SLS_CC); + r->allowed |= (1 << METHODS) - 1; + zend_try { + zend_ini_deactivate(ELS_C); + } zend_end_try(); + return DECLINED; + } + if (filename == NULL) { + filename = r->filename; } - return DECLINED; - } - if (filename == NULL) { - filename = r->filename; - } - /* Apache 1.2 has a more complex mechanism for reading POST data */ + /* Apache 1.2 has a more complex mechanism for reading POST data */ #if MODULE_MAGIC_NUMBER > 19961007 - if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR))) { - if (setjmp(EG(bailout))==0) { - zend_ini_deactivate(ELS_C); + if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR))) { + zend_try { + zend_ini_deactivate(ELS_C); + } zend_end_try(); + return retval; } - return retval; - } #endif - if (AP(last_modified)) { + if (AP(last_modified)) { #if MODULE_MAGIC_NUMBER < 19970912 - if ((retval = set_last_modified(r, r->finfo.st_mtime))) { - if (setjmp(EG(bailout))==0) { - zend_ini_deactivate(ELS_C); + if ((retval = set_last_modified(r, r->finfo.st_mtime))) { + zend_try { + zend_ini_deactivate(ELS_C); + } zend_end_try(); + return retval; } - return retval; - } #else - update_mtime (r, r->finfo.st_mtime); - set_last_modified(r); - set_etag(r); + update_mtime (r, r->finfo.st_mtime); + set_last_modified(r); + set_etag(r); #endif - } - /* Assume output will be of the default MIME type. Individual - scripts may change this later in the request. */ - r->content_type = php_apache_get_default_mimetype(r SLS_CC); + } + /* Assume output will be of the default MIME type. Individual + scripts may change this later in the request. */ + r->content_type = php_apache_get_default_mimetype(r SLS_CC); - /* Init timeout */ - hard_timeout("send", r); + /* Init timeout */ + hard_timeout("send", r); - SG(server_context) = r; - - php_save_umask(); - add_common_vars(r); - add_cgi_vars(r); + SG(server_context) = r; + + php_save_umask(); + add_common_vars(r); + add_cgi_vars(r); + + init_request_info(SLS_C); + apache_php_module_main(r, display_source_mode CLS_CC ELS_CC PLS_CC SLS_CC); - init_request_info(SLS_C); - apache_php_module_main(r, display_source_mode CLS_CC ELS_CC PLS_CC SLS_CC); + /* Done, restore umask, turn off timeout, close file and return */ + php_restore_umask(); + kill_timeout(r); + } zend_end_try(); - /* Done, restore umask, turn off timeout, close file and return */ - php_restore_umask(); - kill_timeout(r); return OK; } /* }}} */ diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c index 90d47da7d6..ef05150842 100644 --- a/sapi/apache/sapi_apache.c +++ b/sapi/apache/sapi_apache.c @@ -89,12 +89,11 @@ int apache_php_module_main(request_rec *r, int display_source_mode CLS_DC ELS_DC (void) php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); } - - if (setjmp(EG(bailout))!=0) { - return OK; + + zend_try { + php_end_ob_buffers(1); + php_header(); /* Make sure headers have been sent */ } - php_end_ob_buffers(1); - php_header(); /* Make sure headers have been sent */ return (OK); } /* }}} */ diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 1ebd67843a..e72483375d 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -398,11 +398,6 @@ int main(int argc, char *argv[]) #endif #endif -#ifndef ZTS - if (setjmp(EG(bailout))!=0) { - return -1; - } -#endif #ifdef ZTS tsrm_startup(1,1,0, NULL); @@ -487,307 +482,308 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine executor_globals = ts_resource(executor_globals_id); core_globals = ts_resource(core_globals_id); sapi_globals = ts_resource(sapi_globals_id); - if (setjmp(EG(bailout))!=0) { - return -1; - } #endif - if (!cgi) { - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case '?': - no_headers = 1; - php_output_startup(); - php_output_activate(); - SG(headers_sent) = 1; - php_cgi_usage(argv[0]); - php_end_ob_buffers(1); - exit(1); - break; + zend_try { + if (!cgi) { + while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { + switch (c) { + case '?': + no_headers = 1; + php_output_startup(); + php_output_activate(); + SG(headers_sent) = 1; + php_cgi_usage(argv[0]); + php_end_ob_buffers(1); + exit(1); + break; + } } + ap_php_optind = orig_optind; + ap_php_optarg = orig_optarg; } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - } - init_request_info(SLS_C); - SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */ - CG(extended_info) = 0; + init_request_info(SLS_C); + SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */ + CG(extended_info) = 0; - SG(request_info).argv0 = argv0; + SG(request_info).argv0 = argv0; - zend_llist_init(&global_vars, sizeof(char *), NULL, 0); + zend_llist_init(&global_vars, sizeof(char *), NULL, 0); - if (!cgi) { /* never execute the arguments if you are a CGI */ - if (SG(request_info).argv0) { - free(SG(request_info).argv0); - SG(request_info).argv0 = NULL; - } - while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { - switch (c) { - - case 'a': /* interactive mode */ - printf("Interactive mode enabled\n\n"); - interactive=1; - break; - - case 'C': /* don't chdir to the script directory */ - SG(options) |= SAPI_OPTION_NO_CHDIR; - break; - case 'd': /* define ini entries on command line */ - define_command_line_ini_entry(ap_php_optarg); - break; + if (!cgi) { /* never execute the arguments if you are a CGI */ + if (SG(request_info).argv0) { + free(SG(request_info).argv0); + SG(request_info).argv0 = NULL; + } + while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { + switch (c) { - case 'e': /* enable extended info output */ - CG(extended_info) = 1; - break; - - case 'f': /* parse file */ - script_file = estrdup(ap_php_optarg); - no_headers = 1; - break; - - case 'g': /* define global variables on command line */ - { - char *arg = estrdup(ap_php_optarg); - - zend_llist_add_element(&global_vars, &arg); - } - break; - - case 'h': /* help & quit */ - case '?': - no_headers = 1; + case 'a': /* interactive mode */ + printf("Interactive mode enabled\n\n"); + interactive=1; + break; + + case 'C': /* don't chdir to the script directory */ + SG(options) |= SAPI_OPTION_NO_CHDIR; + break; + case 'd': /* define ini entries on command line */ + define_command_line_ini_entry(ap_php_optarg); + break; + + case 'e': /* enable extended info output */ + CG(extended_info) = 1; + break; + + case 'f': /* parse file */ + script_file = estrdup(ap_php_optarg); + no_headers = 1; + break; + + case 'g': /* define global variables on command line */ + { + char *arg = estrdup(ap_php_optarg); + + zend_llist_add_element(&global_vars, &arg); + } + break; + + case 'h': /* help & quit */ + case '?': + no_headers = 1; + php_output_startup(); + php_output_activate(); + SG(headers_sent) = 1; + php_cgi_usage(argv[0]); + php_end_ob_buffers(1); + exit(1); + break; + + case 'i': /* php info & quit */ + if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { + php_module_shutdown(); + return FAILURE; + } + if (no_headers) { + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + } + php_print_info(0xFFFFFFFF); + exit(1); + break; + + case 'l': /* syntax check mode */ + no_headers = 1; + behavior=PHP_MODE_LINT; + break; + + case 'm': /* list compiled in modules */ php_output_startup(); php_output_activate(); SG(headers_sent) = 1; - php_cgi_usage(argv[0]); + php_printf("Running PHP %s\n%s\n", PHP_VERSION , get_zend_version()); + php_printf("[PHP Modules]\n"); + zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _print_module_info, NULL); + php_printf("\n[Zend Modules]\n"); + zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) _print_module_info, NULL); + php_printf("\n"); php_end_ob_buffers(1); exit(1); break; - case 'i': /* php info & quit */ - if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { - php_module_shutdown(); - return FAILURE; - } - if (no_headers) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - } - php_print_info(0xFFFFFFFF); - exit(1); - break; - - case 'l': /* syntax check mode */ - no_headers = 1; - behavior=PHP_MODE_LINT; - break; - - case 'm': /* list compiled in modules */ - php_output_startup(); - php_output_activate(); - SG(headers_sent) = 1; - php_printf("Running PHP %s\n%s\n", PHP_VERSION , get_zend_version()); - php_printf("[PHP Modules]\n"); - zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _print_module_info, NULL); - php_printf("\n[Zend Modules]\n"); - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) _print_module_info, NULL); - php_printf("\n"); - php_end_ob_buffers(1); - exit(1); - break; - #if 0 /* not yet operational, see also below ... */ - case 'n': /* generate indented source mode*/ - behavior=PHP_MODE_INDENT; - break; + case 'n': /* generate indented source mode*/ + behavior=PHP_MODE_INDENT; + break; #endif - case 'q': /* do not generate HTTP headers */ - no_headers = 1; - break; - - case 's': /* generate highlighted HTML from source */ - behavior=PHP_MODE_HIGHLIGHT; - break; - - case 'v': /* show php version & quit */ - no_headers = 1; - if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { - php_module_shutdown(); - return FAILURE; - } - if (no_headers) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - } - php_printf("%s\n", PHP_VERSION); - php_end_ob_buffers(1); - exit(1); - break; - - case 'z': /* load extension file */ - zend_load_extension(ap_php_optarg); - break; - - default: - break; + case 'q': /* do not generate HTTP headers */ + no_headers = 1; + break; + + case 's': /* generate highlighted HTML from source */ + behavior=PHP_MODE_HIGHLIGHT; + break; + + case 'v': /* show php version & quit */ + no_headers = 1; + if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { + php_module_shutdown(); + return FAILURE; + } + if (no_headers) { + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + } + php_printf("%s\n", PHP_VERSION); + php_end_ob_buffers(1); + exit(1); + break; + + case 'z': /* load extension file */ + zend_load_extension(ap_php_optarg); + break; + + default: + break; + } } - } - } /* not cgi */ + } /* not cgi */ - CG(interactive) = interactive; + CG(interactive) = interactive; - if (!cgi) { - if (!SG(request_info).query_string) { - len = 0; - if (script_file) { - len += strlen(script_file) + 1; - } - for (i = ap_php_optind; i < argc; i++) { - len += strlen(argv[i]) + 1; - } + if (!cgi) { + if (!SG(request_info).query_string) { + len = 0; + if (script_file) { + len += strlen(script_file) + 1; + } + for (i = ap_php_optind; i < argc; i++) { + len += strlen(argv[i]) + 1; + } - s = malloc(len + 1); /* leak - but only for command line version, so ok */ - *s = '\0'; /* we are pretending it came from the environment */ - if (script_file) { - strcpy(s, script_file); - if (ap_php_optind ap_php_optind) { - SG(request_info).path_translated = estrdup(argv[ap_php_optind]); + if (script_file) { + SG(request_info).path_translated = script_file; } - } else { - /* If for some reason the CGI interface is not setting the - PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL. - We still call php_fopen_primary_script, because if you set doc_root - or user_dir configuration directives, PATH_INFO is used to construct - the filename as a side effect of php_fopen_primary_script. - */ - char *env_path_translated=NULL; -#if DISCARD_PATH - env_path_translated = getenv("SCRIPT_FILENAME"); -#else - env_path_translated = getenv("PATH_TRANSLATED"); -#endif - if(env_path_translated) { - SG(request_info).path_translated = estrdup(env_path_translated); - } - } - if (cgi || SG(request_info).path_translated) { - file_handle.handle.fp = php_fopen_primary_script(); - file_handle.filename = SG(request_info).path_translated; - } - if (cgi && !file_handle.handle.fp) { - if(!argv0 || !(file_handle.handle.fp = VCWD_FOPEN(argv0, "rb"))) { - PUTS("No input file specified.\n"); - php_request_shutdown((void *) 0); + if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { php_module_shutdown(); return FAILURE; } - file_handle.filename = argv0; - } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) { - /* #!php support */ - c = fgetc(file_handle.handle.fp); - if (c == '#') { - while (c != 10 && c != 13) { - c = fgetc(file_handle.handle.fp); /* skip to end of line */ + if (no_headers) { + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + } + file_handle.filename = "-"; + file_handle.type = ZEND_HANDLE_FP; + file_handle.handle.fp = stdin; + file_handle.opened_path = NULL; + + /* This actually destructs the elements of the list - ugly hack */ + zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars); + zend_llist_destroy(&global_vars); + + if (!cgi) { + if (!SG(request_info).path_translated && argc > ap_php_optind) { + SG(request_info).path_translated = estrdup(argv[ap_php_optind]); } - CG(zend_lineno)++; } else { - rewind(file_handle.handle.fp); + /* If for some reason the CGI interface is not setting the + PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL. + We still call php_fopen_primary_script, because if you set doc_root + or user_dir configuration directives, PATH_INFO is used to construct + the filename as a side effect of php_fopen_primary_script. + */ + char *env_path_translated=NULL; +#if DISCARD_PATH + env_path_translated = getenv("SCRIPT_FILENAME"); +#else + env_path_translated = getenv("PATH_TRANSLATED"); +#endif + if(env_path_translated) { + SG(request_info).path_translated = estrdup(env_path_translated); + } + } + if (cgi || SG(request_info).path_translated) { + file_handle.handle.fp = php_fopen_primary_script(); + file_handle.filename = SG(request_info).path_translated; } - } - file_handle.free_filename = 0; - switch (behavior) { - case PHP_MODE_STANDARD: - exit_status = php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); - break; - case PHP_MODE_LINT: - PG(during_request_startup) = 0; - exit_status = php_lint_script(&file_handle CLS_CC ELS_CC PLS_CC); - if (exit_status==SUCCESS) { - zend_printf("No syntax errors detected in %s\n", file_handle.filename); - } else { - zend_printf("Errors parsing %s\n", file_handle.filename); + if (cgi && !file_handle.handle.fp) { + if(!argv0 || !(file_handle.handle.fp = VCWD_FOPEN(argv0, "rb"))) { + PUTS("No input file specified.\n"); + php_request_shutdown((void *) 0); + php_module_shutdown(); + return FAILURE; } - break; - case PHP_MODE_HIGHLIGHT: - { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { - php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini); - fclose(file_handle.handle.fp); + file_handle.filename = argv0; + } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) { + /* #!php support */ + c = fgetc(file_handle.handle.fp); + if (c == '#') { + while (c != 10 && c != 13) { + c = fgetc(file_handle.handle.fp); /* skip to end of line */ } - return SUCCESS; + CG(zend_lineno)++; + } else { + rewind(file_handle.handle.fp); } - break; + } + + file_handle.free_filename = 0; + switch (behavior) { + case PHP_MODE_STANDARD: + exit_status = php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); + break; + case PHP_MODE_LINT: + PG(during_request_startup) = 0; + exit_status = php_lint_script(&file_handle CLS_CC ELS_CC PLS_CC); + if (exit_status==SUCCESS) { + zend_printf("No syntax errors detected in %s\n", file_handle.filename); + } else { + zend_printf("Errors parsing %s\n", file_handle.filename); + } + break; + case PHP_MODE_HIGHLIGHT: + { + zend_syntax_highlighter_ini syntax_highlighter_ini; + + if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { + php_get_highlight_struct(&syntax_highlighter_ini); + zend_highlight(&syntax_highlighter_ini); + fclose(file_handle.handle.fp); + } + return SUCCESS; + } + break; #if 0 - /* Zeev might want to do something with this one day */ - case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle CLS_CC); - zend_indent(); - fclose(file_handle.handle.fp); - return SUCCESS; - break; + /* Zeev might want to do something with this one day */ + case PHP_MODE_INDENT: + open_file_for_scanning(&file_handle CLS_CC); + zend_indent(); + fclose(file_handle.handle.fp); + return SUCCESS; + break; #endif - } + } - if (SG(request_info).path_translated) { - persist_alloc(SG(request_info).path_translated); - } + if (SG(request_info).path_translated) { + persist_alloc(SG(request_info).path_translated); + } - php_request_shutdown((void *) 0); - php_module_shutdown(); + php_request_shutdown((void *) 0); + php_module_shutdown(); - STR_FREE(SG(request_info).path_translated); + STR_FREE(SG(request_info).path_translated); - if (cgi_sapi_module.php_ini_path_override) { - free(cgi_sapi_module.php_ini_path_override); - } + if (cgi_sapi_module.php_ini_path_override) { + free(cgi_sapi_module.php_ini_path_override); + } #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif + } zend_catch { + exit_status = -1; + } zend_end_try(); return exit_status; } diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c index daee230634..c006016cf7 100644 --- a/sapi/isapi/php4isapi.c +++ b/sapi/isapi/php4isapi.c @@ -43,13 +43,16 @@ # define GetLastError() errno #endif +#ifdef PHP_WIN32 +#define PHP_ENABLE_SEH +#endif + /* uncomment the following lines to turn off exception trapping when running under a debugger - #ifdef _DEBUG -#define NO_EXCEPTION_HANDLERS +#undef PHP_ENABLE_SEH #endif */ @@ -701,11 +704,10 @@ static void my_endthread() } #ifdef PHP_WIN32 -/* - ___except can only call a function, so we have to do this - to retrieve the pointer. +/* ep is accessible only in the context of the __except expression, + * so we have to call this function to obtain it. */ -BOOL exceptionhandler(LPEXCEPTION_POINTERS *e,LPEXCEPTION_POINTERS ep) +BOOL exceptionhandler(LPEXCEPTION_POINTERS *e, LPEXCEPTION_POINTERS ep) { *e=ep; return TRUE; @@ -720,107 +722,105 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) CLS_FETCH(); ELS_FETCH(); PLS_FETCH(); -#if !defined (NO_EXCEPTION_HANDLERS) && defined(PHP_WIN32) +#ifdef PHP_ENABLE_SEH LPEXCEPTION_POINTERS e; #endif - if (setjmp(EG(bailout))!=0) { - php_request_shutdown(NULL); - return HSE_STATUS_ERROR; - } - -#if !defined (NO_EXCEPTION_HANDLERS) - __try { + zend_try { +#ifdef PHP_ENABLE_SEH + __try { #endif - init_request_info(sapi_globals, lpECB); - SG(server_context) = lpECB; + init_request_info(sapi_globals, lpECB); + SG(server_context) = lpECB; #ifdef WITH_ZEUS - /* PATH_TRANSLATED can contain extra PATH_INFO stuff after the - * file being loaded, so we must use SCRIPT_FILENAME instead - */ - file_handle.filename = (char *)emalloc( ISAPI_SERVER_VAR_BUF_SIZE ); - file_handle.free_filename = 1; - { - DWORD filename_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( !lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", file_handle.filename, &filename_len) || file_handle.filename[ 0 ] == '\0' ) { - /* If we're running on an earlier version of Zeus, this - * variable won't be present, so fall back to old behaviour. - */ - efree( file_handle.filename ); - file_handle.filename = sapi_globals->request_info.path_translated; - file_handle.free_filename = 0; - } - } + /* PATH_TRANSLATED can contain extra PATH_INFO stuff after the + * file being loaded, so we must use SCRIPT_FILENAME instead + */ + file_handle.filename = (char *)emalloc( ISAPI_SERVER_VAR_BUF_SIZE ); + file_handle.free_filename = 1; + { + DWORD filename_len = ISAPI_SERVER_VAR_BUF_SIZE; + if( !lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", file_handle.filename, &filename_len) || file_handle.filename[ 0 ] == '\0' ) { + /* If we're running on an earlier version of Zeus, this + * variable won't be present, so fall back to old behaviour. + */ + efree( file_handle.filename ); + file_handle.filename = sapi_globals->request_info.path_translated; + file_handle.free_filename = 0; + } + } #else - file_handle.filename = sapi_globals->request_info.path_translated; - file_handle.free_filename = 0; + file_handle.filename = sapi_globals->request_info.path_translated; + file_handle.free_filename = 0; #endif - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; + file_handle.type = ZEND_HANDLE_FILENAME; + file_handle.opened_path = NULL; - php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); - php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); - if (SG(request_info).cookie_data) { - efree(SG(request_info).cookie_data); - } -#if !defined (NO_EXCEPTION_HANDLERS) -#ifdef PHP_WIN32 - } __except(exceptionhandler(&e,GetExceptionInformation())) { -#else - } __except(EXCEPTION_EXECUTE_HANDLER) { -#endif -#ifdef PHP_WIN32 - char buf[1024]; - if (_exception_code()==EXCEPTION_STACK_OVERFLOW) { - LPBYTE lpPage; - static SYSTEM_INFO si; - static MEMORY_BASIC_INFORMATION mi; - static DWORD dwOldProtect; + php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); + php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); + if (SG(request_info).cookie_data) { + efree(SG(request_info).cookie_data); + } +#ifdef PHP_ENABLE_SEH + } __except(exceptionhandler(&e, GetExceptionInformation())) { + char buf[1024]; + if (_exception_code()==EXCEPTION_STACK_OVERFLOW) { + LPBYTE lpPage; + static SYSTEM_INFO si; + static MEMORY_BASIC_INFORMATION mi; + static DWORD dwOldProtect; - GetSystemInfo(&si); + GetSystemInfo(&si); - /* Get page ESP is pointing to */ - _asm mov lpPage, esp; + /* Get page ESP is pointing to */ + _asm mov lpPage, esp; - /* Get stack allocation base */ - VirtualQuery(lpPage, &mi, sizeof(mi)); + /* Get stack allocation base */ + VirtualQuery(lpPage, &mi, sizeof(mi)); - /* Go to the page below the current page */ - lpPage = (LPBYTE) (mi.BaseAddress) - si.dwPageSize; + /* Go to the page below the current page */ + lpPage = (LPBYTE) (mi.BaseAddress) - si.dwPageSize; - /* Free pages below current page */ - if (!VirtualFree(mi.AllocationBase, (LPBYTE)lpPage - (LPBYTE) mi.AllocationBase, MEM_DECOMMIT)) { - _endthread(); - } + /* Free pages below current page */ + if (!VirtualFree(mi.AllocationBase, (LPBYTE)lpPage - (LPBYTE) mi.AllocationBase, MEM_DECOMMIT)) { + _endthread(); + } - /* Restore the guard page */ - if (!VirtualProtect(lpPage, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &dwOldProtect)) { - _endthread(); - } + /* Restore the guard page */ + if (!VirtualProtect(lpPage, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &dwOldProtect)) { + _endthread(); + } - CG(unclean_shutdown)=1; - _snprintf(buf,sizeof(buf)-1,"PHP has encountered a Stack overflow"); - php_isapi_report_exception(buf, strlen(buf) SLS_CC); - } else if (_exception_code()==EXCEPTION_ACCESS_VIOLATION) { - _snprintf(buf,sizeof(buf)-1,"PHP has encountered an Access Violation at %p",e->ExceptionRecord->ExceptionAddress); - php_isapi_report_exception(buf, strlen(buf) SLS_CC); - my_endthread(); - } else { - _snprintf(buf,sizeof(buf)-1,"PHP has encountered an Unhandled Exception Code %d at %p",e->ExceptionRecord->ExceptionCode , e->ExceptionRecord->ExceptionAddress); - php_isapi_report_exception(buf, strlen(buf) SLS_CC); + CG(unclean_shutdown)=1; + _snprintf(buf,sizeof(buf)-1,"PHP has encountered a Stack overflow"); + php_isapi_report_exception(buf, strlen(buf) SLS_CC); + } else if (_exception_code()==EXCEPTION_ACCESS_VIOLATION) { + _snprintf(buf,sizeof(buf)-1,"PHP has encountered an Access Violation at %p",e->ExceptionRecord->ExceptionAddress); + php_isapi_report_exception(buf, strlen(buf) SLS_CC); + my_endthread(); + } else { + _snprintf(buf,sizeof(buf)-1,"PHP has encountered an Unhandled Exception Code %d at %p",e->ExceptionRecord->ExceptionCode , e->ExceptionRecord->ExceptionAddress); + php_isapi_report_exception(buf, strlen(buf) SLS_CC); + my_endthread(); + } +#endif + } +#ifdef PHP_ENABLE_SEH + __try { + php_request_shutdown(NULL); + } __except(EXCEPTION_EXECUTE_HANDLER) { my_endthread(); } -#endif - } - __try { - php_request_shutdown(NULL); - } __except(EXCEPTION_EXECUTE_HANDLER) { - my_endthread(); - } #else php_request_shutdown(NULL); #endif + } zend_catch { + zend_try { + php_request_shutdown(NULL); + } zend_end_try(); + return HSE_STATUS_ERROR; + } zend_end_try(); return HSE_STATUS_SUCCESS; } diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c index eef6920506..362ec133fc 100644 --- a/sapi/pi3web/pi3web_sapi.c +++ b/sapi/pi3web/pi3web_sapi.c @@ -382,63 +382,65 @@ DWORD PHP4_wrapper(LPCONTROL_BLOCK lpCB) ELS_FETCH(); PLS_FETCH(); - if (setjmp( EG(bailout)) != 0 ) return PIAPI_ERROR; - - file_handle.filename = lpCB->lpszFileName; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - - CG(extended_info) = 0; - init_request_info(sapi_globals, lpCB); - php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); - - hash_pi3web_variables(ELS_C SLS_CC); - - switch ( lpCB->dwBehavior ) { - case PHP_MODE_STANDARD: - iRet = ( php_execute_script( &file_handle CLS_CC ELS_CC PLS_CC ) == SUCCESS ) ? - PIAPI_COMPLETED : PIAPI_ERROR; - break; - case PHP_MODE_HIGHLIGHT: { - zend_syntax_highlighter_ini syntax_highlighter_ini; - if ( open_file_for_scanning( &file_handle CLS_CC ) == SUCCESS ) - { - php_get_highlight_struct( &syntax_highlighter_ini ); - zend_highlight( &syntax_highlighter_ini ); - } - else - { - iRet = PIAPI_ERROR; - }; - }; - break; - case PHP_MODE_INDENT: - header_line = (char *)estrdup("Content-Type: text/plain"); - sapi_add_header_ex(header_line, strlen(header_line), 1, 1); - if ( open_file_for_scanning( &file_handle CLS_CC ) == SUCCESS ) - { - zend_indent(); - } - else - { - iRet = PIAPI_ERROR; + zend_try { + file_handle.filename = lpCB->lpszFileName; + file_handle.free_filename = 0; + file_handle.type = ZEND_HANDLE_FILENAME; + file_handle.opened_path = NULL; + + CG(extended_info) = 0; + init_request_info(sapi_globals, lpCB); + php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); + + hash_pi3web_variables(ELS_C SLS_CC); + + switch ( lpCB->dwBehavior ) { + case PHP_MODE_STANDARD: + iRet = ( php_execute_script( &file_handle CLS_CC ELS_CC PLS_CC ) == SUCCESS ) ? + PIAPI_COMPLETED : PIAPI_ERROR; + break; + case PHP_MODE_HIGHLIGHT: { + zend_syntax_highlighter_ini syntax_highlighter_ini; + if ( open_file_for_scanning( &file_handle CLS_CC ) == SUCCESS ) + { + php_get_highlight_struct( &syntax_highlighter_ini ); + zend_highlight( &syntax_highlighter_ini ); + } + else + { + iRet = PIAPI_ERROR; + }; }; - efree(header_line); - break; - case PHP_MODE_LINT: - iRet = (php_lint_script(&file_handle CLS_CC ELS_CC PLS_CC) == SUCCESS) ? - PIAPI_COMPLETED : PIAPI_ERROR; - break; - default: - iRet = PIAPI_ERROR;; - } + break; + case PHP_MODE_INDENT: + header_line = (char *)estrdup("Content-Type: text/plain"); + sapi_add_header_ex(header_line, strlen(header_line), 1, 1); + if ( open_file_for_scanning( &file_handle CLS_CC ) == SUCCESS ) + { + zend_indent(); + } + else + { + iRet = PIAPI_ERROR; + }; + efree(header_line); + break; + case PHP_MODE_LINT: + iRet = (php_lint_script(&file_handle CLS_CC ELS_CC PLS_CC) == SUCCESS) ? + PIAPI_COMPLETED : PIAPI_ERROR; + break; + default: + iRet = PIAPI_ERROR;; + } - if (SG(request_info).cookie_data) { - efree(SG(request_info).cookie_data); - }; + if (SG(request_info).cookie_data) { + efree(SG(request_info).cookie_data); + }; - php_request_shutdown(NULL); + php_request_shutdown(NULL); + } zend_catch { + iRet = PIAPI_ERROR; + } zend_end_try(); return iRet; } diff --git a/sapi/servlet/servlet.c b/sapi/servlet/servlet.c index cc5e583c5e..385795e704 100644 --- a/sapi/servlet/servlet.c +++ b/sapi/servlet/servlet.c @@ -251,11 +251,6 @@ JNIEXPORT void JNICALL Java_net_php_servlet_startup #ifdef ZTS tsrm_startup(1, 1, 0, NULL); -#else - if (setjmp(EG(bailout))!=0) { - ThrowServletException(jenv,"bailout"); - return; - } #endif sapi_startup(&servlet_sapi_module); @@ -319,7 +314,6 @@ JNIEXPORT void JNICALL Java_net_php_servlet_send jstring contentType, jint contentLength, jstring authUser, jboolean display_source_mode) { - zend_file_handle file_handle; #ifndef VIRTUAL_DIR char cwd[MAXPATHLEN]; @@ -329,95 +323,92 @@ JNIEXPORT void JNICALL Java_net_php_servlet_send CLS_FETCH(); ELS_FETCH(); -#ifdef ZTS - if (setjmp(EG(bailout))!=0) { - ThrowServletException(jenv,"bailout"); - return; - } -#endif - - SG(server_context) = emalloc(sizeof(servlet_request)); - ((servlet_request*)SG(server_context))->jenv=jenv; - ((servlet_request*)SG(server_context))->servlet=self; - ((servlet_request*)SG(server_context))->cookies=0; - - CG(extended_info) = 0; - - /* - * Initialize the request - */ - SETSTRING( SG(request_info).auth_user, authUser ); - SETSTRING( SG(request_info).request_method, requestMethod ); - SETSTRING( SG(request_info).query_string, queryString ); - SETSTRING( SG(request_info).request_uri, requestURI ); - SETSTRING( SG(request_info).content_type, contentType ); - SG(sapi_headers).http_response_code = 200; - SG(request_info).content_length = contentLength; - SG(request_info).auth_password = NULL; - if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { - ThrowServletException(jenv,"request startup failure"); - return; - } - - /* - * Parse the file - */ - SETSTRING( SG(request_info).path_translated, pathTranslated ); + zend_try { + SG(server_context) = emalloc(sizeof(servlet_request)); + ((servlet_request*)SG(server_context))->jenv=jenv; + ((servlet_request*)SG(server_context))->servlet=self; + ((servlet_request*)SG(server_context))->cookies=0; + + CG(extended_info) = 0; + + /* + * Initialize the request + */ + SETSTRING( SG(request_info).auth_user, authUser ); + SETSTRING( SG(request_info).request_method, requestMethod ); + SETSTRING( SG(request_info).query_string, queryString ); + SETSTRING( SG(request_info).request_uri, requestURI ); + SETSTRING( SG(request_info).content_type, contentType ); + SG(sapi_headers).http_response_code = 200; + SG(request_info).content_length = contentLength; + SG(request_info).auth_password = NULL; + if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) { + ThrowServletException(jenv,"request startup failure"); + return; + } + + /* + * Parse the file + */ + SETSTRING( SG(request_info).path_translated, pathTranslated ); #ifdef VIRTUAL_DIR - file_handle.handle.fp = php_fopen_primary_script(); + file_handle.handle.fp = php_fopen_primary_script(); #else - /* - * The java runtime doesn't like the working directory to be - * changed, so save it and change it back as quickly as possible - * in the hopes that Java doesn't notice. - */ - getcwd(cwd,MAXPATHLEN); - file_handle.handle.fp = php_fopen_primary_script(); - chdir(cwd); + /* + * The java runtime doesn't like the working directory to be + * changed, so save it and change it back as quickly as possible + * in the hopes that Java doesn't notice. + */ + getcwd(cwd,MAXPATHLEN); + file_handle.handle.fp = php_fopen_primary_script(); + chdir(cwd); #endif - file_handle.filename = SG(request_info).path_translated; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FP; - - if (!file_handle.handle.fp) { - php_request_shutdown((void *) 0); - php_module_shutdown(); - ThrowIOException(jenv,file_handle.filename); - return; - } - - /* - * Execute the request - */ - Java_net_php_reflect_setEnv(jenv, 0); - - if (display_source_mode) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { - php_get_highlight_struct(&syntax_highlighter_ini); - sapi_send_headers(); - zend_highlight(&syntax_highlighter_ini); - } - } else { - php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); - php_header(); /* Make sure headers have been sent */ - } - - /* - * Clean up - */ - - FREESTRING(SG(request_info).request_method); - FREESTRING(SG(request_info).query_string); - FREESTRING(SG(request_info).request_uri); - FREESTRING(SG(request_info).path_translated); - FREESTRING(SG(request_info).content_type); - FREESTRING(((servlet_request*)SG(server_context))->cookies); - efree(SG(server_context)); - SG(server_context)=0; - - if (!display_source_mode) php_request_shutdown((void *) 0); + file_handle.filename = SG(request_info).path_translated; + file_handle.opened_path = NULL; + file_handle.free_filename = 0; + file_handle.type = ZEND_HANDLE_FP; + + if (!file_handle.handle.fp) { + php_request_shutdown((void *) 0); + php_module_shutdown(); + ThrowIOException(jenv,file_handle.filename); + return; + } + + /* + * Execute the request + */ + Java_net_php_reflect_setEnv(jenv, 0); + + if (display_source_mode) { + zend_syntax_highlighter_ini syntax_highlighter_ini; + + if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { + php_get_highlight_struct(&syntax_highlighter_ini); + sapi_send_headers(); + zend_highlight(&syntax_highlighter_ini); + } + } else { + php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); + php_header(); /* Make sure headers have been sent */ + } + + /* + * Clean up + */ + + FREESTRING(SG(request_info).request_method); + FREESTRING(SG(request_info).query_string); + FREESTRING(SG(request_info).request_uri); + FREESTRING(SG(request_info).path_translated); + FREESTRING(SG(request_info).content_type); + FREESTRING(((servlet_request*)SG(server_context))->cookies); + efree(SG(server_context)); + SG(server_context)=0; + + if (!display_source_mode) php_request_shutdown((void *) 0); + } zend_catch { + ThrowServletException(jenv,"bailout"); + } zend_end_try(); } -- 2.40.0