From: Dmitry Stogov Date: Mon, 24 Sep 2007 11:40:05 +0000 (+0000) Subject: Fixed bug #42699 (PHP_SELF duplicates path) X-Git-Tag: php-5.2.5RC1~95 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b441b275b35f64414a131aefafffb56e69817393;p=php Fixed bug #42699 (PHP_SELF duplicates path) --- diff --git a/NEWS b/NEWS index 4b61793ca4..2ce53a136c 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,7 @@ PHP NEWS - Fixed bug #42739 (mkdir() doesnt like a trailing slash when safe_mode is enabled). (Ilia) +- Fixed bug #42699 (PHP_SELF duplicates path). (Dmitry) - Fixed bug #42643 (CLI segfaults if using ATTR_PERSISTENT). (Ilia) - Fixed bug #42629 (Dynamically loaded PHP extensions need symbols exported on MacOSX). (jdolecek at NetBSD dot org) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 21451cb0e6..601938aed4 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -522,29 +522,44 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC) static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) { - char *script_name = SG(request_info).request_uri; - unsigned int script_name_len = script_name ? strlen(script_name) : 0; - char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC); - unsigned int path_info_len = path_info ? strlen(path_info) : 0; - unsigned int php_self_len = script_name_len + path_info_len; - char *php_self = emalloc(php_self_len + 1); - - if (script_name) { - memcpy(php_self, script_name, script_name_len + 1); - } - if (path_info) { - memcpy(php_self + script_name_len, path_info, path_info_len + 1); - } + unsigned int php_self_len; + char *php_self; /* In CGI mode, we consider the environment to be a part of the server * variables */ php_import_environment_variables(track_vars_array TSRMLS_CC); - /* Build the special-case PHP_SELF variable for the CGI version */ + +#if ENABLE_PATHINFO_CHECK + if (CGIG(fix_pathinfo)) { + char *script_name = SG(request_info).request_uri; + unsigned int script_name_len = script_name ? strlen(script_name) : 0; + char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC); + unsigned int path_info_len = path_info ? strlen(path_info) : 0; + + php_self_len = script_name_len + path_info_len; + php_self = emalloc(php_self_len + 1); + if (script_name) { + memcpy(php_self, script_name, script_name_len + 1); + } + if (path_info) { + memcpy(php_self + script_name_len, path_info, path_info_len + 1); + } + + /* Build the special-case PHP_SELF variable for the CGI version */ + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) { + php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC); + } + efree(php_self); + return; + } +#endif + + php_self = SG(request_info).request_uri ? SG(request_info).request_uri : ""; + php_self_len = strlen(php_self); if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len TSRMLS_CC)) { php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array TSRMLS_CC); } - efree(php_self); } static void sapi_cgi_log_message(char *message)