php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #54152
Patch mod_proxy_fcgi-support-v3.patch revision 2011-03-07 18:49 UTC by jimjag@php.net
Patch mod_proxy_fcgi-support-v2.patch revision 2011-03-07 17:37 UTC by mark at catseye dot org
Patch mod_proxy_fcgi-support.patch revision 2011-03-03 18:56 UTC by mark at catseye dot org

Patch mod_proxy_fcgi-support-v3.patch for FPM related Bug #54152

Patch version 2011-03-07 18:49 UTC

Return to Bug #54152 | Download this patch
Patch Revisions:

Developer: jimjag@php.net

Index: sapi/fpm/fpm/fpm_main.c
===================================================================
--- sapi/fpm/fpm/fpm_main.c	(revision 308995)
+++ sapi/fpm/fpm/fpm_main.c	(working copy)
@@ -1085,6 +1085,7 @@
 	char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", sizeof("PATH_TRANSLATED")-1 TSRMLS_CC);
 	char *script_path_translated = env_script_filename;
 	char *ini;
+	int apache_was_here = 0;
 
 	/* some broken servers do not have script_filename or argv0
 	 * an example, IIS configured in some ways.  then they do more
@@ -1130,6 +1131,30 @@
 			env_path_info = _sapi_cgibin_putenv("PATH_INFO", env_path_info TSRMLS_CC);
 		}
 
+#define APACHE_PROXY_FCGI_PREFIX "proxy:fcgi://"
+		/* Fix proxy URLs in SCRIPT_FILENAME generated by Apache mod_proxy_fcgi:
+		 *     proxy:fcgi://localhost:9000/some-dir/info.php/test
+		 * should be changed to:
+		 *     /some-dir/info.php/test
+		 * See: http://bugs.php.net/bug.php?id=54152
+		 *      https://issues.apache.org/bugzilla/show_bug.cgi?id=50851
+		 */
+		if (env_script_filename &&
+			strncasecmp(env_script_filename, APACHE_PROXY_FCGI_PREFIX, sizeof(APACHE_PROXY_FCGI_PREFIX) - 1) == 0) {
+			/* advance to first character of hostname */
+			char *p = env_script_filename + (sizeof(APACHE_PROXY_FCGI_PREFIX) - 1);
+			while (*p != '\0' && *p != '/') {
+				p++;	/* move past hostname and port */
+			}
+			if (*p != '\0') {
+				/* Copy path portion in place to avoid memory leak.  Note
+				 * that this also affects what script_path_translated points
+				 * to. */
+				memmove(env_script_filename, p, strlen(p) + 1);
+				apache_was_here = 1;
+			}
+		}
+
 		if (CGIG(fix_pathinfo)) {
 			struct stat st;
 			char *real_path = NULL;
@@ -1201,11 +1226,21 @@
 						 * we have to play the game of hide and seek to figure
 						 * out what SCRIPT_NAME should be
 						 */
-						int slen = len - strlen(pt);
+						int ptlen = strlen(pt);
+						int slen = len - ptlen;
 						int pilen = env_path_info ? strlen(env_path_info) : 0;
-						char *path_info = env_path_info ? env_path_info + pilen - slen : NULL;
+						int tflag = 0;
+						char *path_info;
+						if (apache_was_here) {
+							/* recall that PATH_INFO won't exist */
+							path_info = script_path_translated + ptlen;
+							tflag = (slen != 0 && (!orig_path_info || strcmp(orig_path_info, path_info) != 0));
+						} else {
+							path_info = env_path_info ? env_path_info + pilen - slen : NULL;
+							tflag = (orig_path_info != path_info);
+						}
 
-						if (orig_path_info != path_info) {
+						if (tflag) {
 							if (orig_path_info) {
 								char old;
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 19:01:29 2024 UTC