com php-src: Fixed bug #65641 PHP-FPM incorrectly defines the SCRIPT_NAME variable when using Apache: sapi/fpm/ fpm/fpm_main.c
| From: | Remi Collet | Date: | Mon, 15 Sep 2014 11:29:55 +0000 |
| Subject: | com php-src: Fixed bug #65641 PHP-FPM incorrectly defines the SCRIPT_NAME variable when using Apache: sapi/fpm/ fpm/fpm_main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81646@lists.php.net to get a copy of this message | ||
Commit: 8cac75969e5abb2b6be5bbd489d851a4f9e50979
Author: Remi Collet <remi@php.net> Mon, 15 Sep 2014 13:29:55 +0200
Parents: 24b41a23b376636c7f6c7bda5954db994332b44d
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8cac75969e5abb2b6be5bbd489d851a4f9e50979
Log:
Fixed bug #65641 PHP-FPM incorrectly defines the SCRIPT_NAME variable when using Apache
ProxyPass is unable to provide correct PATH_INFO
as it is not aware of file path (while SetHandler is).
As we can extract PATH_INFO from PATH_TRANSLATED,
we also need to check if present in SCRIPT_NAME
and remove it.
After applying this patch.
With mod_php
_SERVER["REQUEST_URI"] /info..php/foo/bar?q=1
_SERVER["SCRIPT_NAME"] /info.php
_SERVER["PATH_INFO"] /foor/bar
_SERVER["PHP_SELF"] /info.php/foo/bar
_SERVER["QUERY_STRING"] q=1
With mod_proxy_fcgi + SetHandler
_SERVER["REQUEST_URI"] /info.php/foo/bar?q=1
_SERVER["SCRIPT_NAME"] /info.php
_SERVER["PATH_INFO"] /foo/bar
_SERVER["PHP_SELF"] /info.php/foo/bar
_SERVER["QUERY_STRING"] q=1
With mod_proxy_fcgi + ProxyPass
_SERVER["REQUEST_URI"] /info.php/foo/bar?q=1
_SERVER["SCRIPT_NAME"] /info.php
_SERVER["PATH_INFO"] /foo/bar
_SERVER["PHP_SELF"] /info.php/foo/bar
_SERVER["QUERY_STRING"] q=1
Bugs:
https://bugs.php.net/65641
Changed paths:
M sapi/fpm/fpm/fpm_main.c
Diff:
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index 56a06f9..331342c 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -1231,6 +1231,17 @@ static void init_request_info(TSRMLS_D)
SG(request_info).request_uri = orig_script_name;
}
path_info[0] = old;
+ } else if (apache_was_here && env_script_name) {
+ /* Using mod_proxy_fcgi and ProxyPass, apache cannot set PATH_INFO
+ * As we can extract PATH_INFO from PATH_TRANSLATED
+ * it is probably also in SCRIPT_NAME and need to be removed
+ */
+ int snlen = strlen(env_script_name);
+ if (snlen>slen && !strcmp(env_script_name+snlen-slen, path_info)) {
+ _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC);
+ env_script_name[snlen-slen] = 0;
+ SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME",
env_script_name TSRMLS_CC);
+ }
}
env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC);
}