From: Xinchen Hui Date: Mon, 30 Apr 2012 04:15:43 +0000 (+0800) Subject: Merge remote-tracking branch 'origin/PHP-5.3' into PHP-5.4 X-Git-Tag: php-5.4.4RC1~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd518ffc7e37a884ced4d34088a6b6c507fd88c2;p=php Merge remote-tracking branch 'origin/PHP-5.3' into PHP-5.4 * origin/PHP-5.3: Fixed bug #61546 (functions related to current script failed when chdir() in cli sapi). - BFN Conflicts: sapi/cli/php_cli.c --- fd518ffc7e37a884ced4d34088a6b6c507fd88c2 diff --cc NEWS index 057e1aab1b,7bb6cc0719..11251ebf40 --- a/NEWS +++ b/NEWS @@@ -1,15 -1,10 +1,17 @@@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -?? ??? 2012, PHP 5.3.12 +?? ??? 2012, PHP 5.4.1 RC1 -- CLI SAPI: +- CLI Server: + . Fixed bug #61546 (functions related to current script failed when chdir() + in cli sapi). (Laruence, reeze.xia@gmail.com) + . Improved performance while sending error page, this also fixed + bug #61785 (Memory leak when access a non-exists file without router). + (Laruence) + . Fixed bug #61461 (missing checks around malloc() calls). (Ilia) + . Implemented FR #60850 (Built in web server does not set + $_SERVER['SCRIPT_FILENAME'] when using router). (Laruence) + . "Connection: close" instead of "Connection: closed" (Gustavo) - Core: . Fixed missing bound check in iptcparse(). (chris at chiappa.net) diff --cc sapi/cli/php_cli.c index 801e53ba24,f26db43151..205b9db3fe --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@@ -650,26 -631,154 +650,26 @@@ static int cli_seek_file_begin(zend_fil } /* }}} */ -/* {{{ main - */ -#ifdef PHP_CLI_WIN32_NO_CONSOLE -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) -#else -int main(int argc, char *argv[]) -#endif +static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ { - volatile int exit_status = SUCCESS; int c; zend_file_handle file_handle; -/* temporary locals */ - int behavior=PHP_MODE_STANDARD; + int behavior = PHP_MODE_STANDARD; char *reflection_what = NULL; - int orig_optind=php_optind; - char *orig_optarg=php_optarg; + volatile int request_started = 0; + volatile int exit_status = 0; + char *php_optarg = NULL, *orig_optarg = NULL; + int php_optind = 1, orig_optind = 1; + char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL; char *arg_free=NULL, **arg_excp=&arg_free; - char *script_file=NULL; + char *script_file=NULL, *translated_path = NULL; int interactive=0; - volatile int module_started = 0; - volatile int request_started = 0; int lineno = 0; - char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL; const char *param_error=NULL; int hide_argv = 0; -/* end of temporary locals */ -#ifdef ZTS - void ***tsrm_ls; -#endif -#ifdef PHP_CLI_WIN32_NO_CONSOLE - int argc = __argc; - char **argv = __argv; -#endif - int ini_entries_len = 0; - -#if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) - { - int tmp_flag; - _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); - tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmp_flag |= _CRTDBG_LEAK_CHECK_DF; - - _CrtSetDbgFlag(tmp_flag); - } -#endif - -#ifdef HAVE_SIGNAL_H -#if defined(SIGPIPE) && defined(SIG_IGN) - signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so - that sockets created via fsockopen() - don't kill PHP if the remote site - closes it. in apache|apxs mode apache - does that for us! thies@thieso.net - 20000419 */ -#endif -#endif - - -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); - tsrm_ls = ts_resource(0); -#endif - - cli_sapi_module.ini_defaults = sapi_cli_ini_defaults; - cli_sapi_module.php_ini_path_override = NULL; - cli_sapi_module.phpinfo_as_text = 1; - sapi_startup(&cli_sapi_module); - -#ifdef PHP_WIN32 - _fmode = _O_BINARY; /*sets default for file streams to binary */ - setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ -#endif - ini_entries_len = sizeof(HARDCODED_INI)-2; - cli_sapi_module.ini_entries = malloc(sizeof(HARDCODED_INI)); - memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI)); - - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2))!=-1) { - switch (c) { - case 'c': - if (cli_sapi_module.php_ini_path_override) { - free(cli_sapi_module.php_ini_path_override); - } - cli_sapi_module.php_ini_path_override = strdup(php_optarg); - break; - case 'n': - cli_sapi_module.php_ini_ignore = 1; - break; - case 'd': { - /* define ini entries on command line */ - int len = strlen(php_optarg); - char *val; - - if ((val = strchr(php_optarg, '='))) { - val++; - if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { - cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (val - php_optarg); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, "\"", 1); - ini_entries_len++; - memcpy(cli_sapi_module.ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (val - php_optarg); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); - ini_entries_len += sizeof("\n\0\"") - 2; - } else { - cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("\n\0")); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, len); - memcpy(cli_sapi_module.ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0")); - ini_entries_len += len + sizeof("\n\0") - 2; - } - } else { - cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("=1\n\0")); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, len); - memcpy(cli_sapi_module.ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0")); - ini_entries_len += len + sizeof("=1\n\0") - 2; - } - break; - } - } - } - php_optind = orig_optind; - php_optarg = orig_optarg; - - cli_sapi_module.executable_location = argv[0]; - cli_sapi_module.additional_functions = additional_functions; - - /* startup after we get the above ini override se we get things right */ - if (cli_sapi_module.startup(&cli_sapi_module)==FAILURE) { - /* there is no way to see if we must call zend_ini_deactivate() - * since we cannot check if EG(ini_directives) has been initialised - * because the executor's constructor does not set initialize it. - * Apart from that there seems no need for zend_ini_deactivate() yet. - * So we goto out_err.*/ - exit_status = 1; - goto out_err; - } - module_started = 1; - - zend_first_try { + zend_try { + CG(in_compilation) = 0; /* not initialized but needed for several options */ EG(uninitialized_zval_ptr) = NULL; @@@ -947,8 -1078,8 +952,8 @@@ SG(request_info).argc=argc-php_optind+1; arg_excp = argv+php_optind-1; arg_free = argv[php_optind-1]; - SG(request_info).path_translated = (char*)file_handle.filename; - SG(request_info).path_translated = translated_path? translated_path : file_handle.filename; - argv[php_optind-1] = file_handle.filename; ++ SG(request_info).path_translated = translated_path? translated_path: (char*)file_handle.filename; + argv[php_optind-1] = (char*)file_handle.filename; SG(request_info).argv=argv+php_optind-1; if (php_request_startup(TSRMLS_C)==FAILURE) {