#20226 [NEW]: can't do "foo.php/path.inf" via cgi (with patch)

From: Date: Sun, 03 Nov 2002 11:36:42 +0000
Subject: #20226 [NEW]: can't do "foo.php/path.inf" via cgi (with patch)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23977@lists.php.net to get a copy of this message
From:             tom@tomclegg.net
Operating system: Unix
PHP version:      4.2.3
PHP Bug Type:     Feature/Change Request
Bug description:  can't do "foo.php/path.inf" via cgi (with patch)

I use php as a cgi usuing Apache's "Action" directive.  If I put a script
in /u/joe/pub/example.php and visit http://joe/example.php/foo then Apache
puts /example.php/foo in PATH_INFO, and PHP tries to open
/u/joe/pub/example.php/foo.  (Internal server error; premature end of
script headers)

This patch checks /u, /u/joe, /u/joe/pub, etc.; if one of them is a
regular file (in this case /u/joe/pub/example.php) then that file is used
as the script filename.  Now the script runs, with the entire PATH_INFO
passed to it.  (It's up to the script to figure out which part to
ignore.)

--- main/fopen_wrappers.c.orig	Fri Aug 23 01:00:49 2002
+++ main/fopen_wrappers.c	Sun Nov  3 02:54:26 2002
@@ -388,6 +388,23 @@
 		SG(request_info).path_translated = NULL;
 		return FAILURE;
 	}
+
+	/* check for /home/joe/public_html/example.php/pathinfo */
+	if (1) {
+		char *s;
+		for (s=filename+1; *s; s++) {
+			if (*s == PHP_DIR_SEPARATOR && *(s-1) != PHP_DIR_SEPARATOR) {
+				*s = 0;
+				if (0 == stat (filename, &st)) {
+					if (S_ISREG(st.st_mode)) {
+						break;
+					}
+				}
+				*s = PHP_DIR_SEPARATOR;
+			}
+		}
+	}
+
 	fp = VCWD_FOPEN(filename, "rb");
 
 	/* refuse to open anything that is not a regular file */

-- 
Edit bug report at http://bugs.php.net/?id=20226&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=20226&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=20226&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=20226&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=20226&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=20226&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=20226&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=20226&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=20226&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=20226&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=20226&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20226&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=20226&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=20226&r=isapi



Thread (3 messages)

« previous php.bugs (#23977) next »