httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject Patch for SCRIPT_NAME/PATH_INFO... ?
Date Wed, 07 Aug 1996 22:04:37 GMT
On Monday I posted here a patch to fix the problems with SCRIPT_NAME and
PATH_INFO when you rewrite URLs with path infos, without breaking existing
scripts or creating new problems in the meantime. 

I have not yet heard any comments on the patch. It may change Apache's CGI
and includes behavior in subtle ways, and I would really like people to
at least glance at it. On the other hand, this problem really does need to
be fixed, sooner rather than later, as it becomes easier and easier to
map URLs to weird filenames. Core dumping, as Apache does not, is
defenitely not the correct behavior, I assume we can all agree with that.

At any rate, here's the patch again. I'd appreciate comments, concerns,
death threats, +1 votes, or whatever.

Index: util_script.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.c,v
retrieving revision 1.16
diff -c -r1.16 util_script.c
*** util_script.c	1996/08/02 20:39:16	1.16
--- util_script.c	1996/08/05 22:41:14
***************
*** 192,197 ****
--- 192,214 ----
      }
  }
  
+ /* This "cute" little function comes about because the path info on
+  * filenames and URLs aren't always the same. So we take the two,
+  * and find as much of the two that match as possible.
+  */
+ 
+ static int find_path_info (char *uri, char *path_info)
+ {
+     int lu = strlen(uri);
+     int lp = strlen(path_info);
+ 
+     while (lu-- && lp-- && uri[lu] == path_info[lp]);
+ 
+     while (uri[lu] != '\0' && uri[lu] != '/')
+ 	lu++;
+ 
+     return lu;
+ }
  
  void add_cgi_vars(request_rec *r)
  {
***************
*** 211,221 ****
      if (!r->path_info || !*r->path_info || !strcmp (r->protocol, "INCLUDED")) {
          table_set (e, "SCRIPT_NAME", r->uri);
      } else {
!         int path_info_start = strlen (r->uri) - strlen (r->path_info);
! 	
! 	r->uri[path_info_start] = '\0';
! 	table_set (e, "SCRIPT_NAME", r->uri);
! 	r->uri[path_info_start] = '/';
      }
  	
      if (r->path_info && r->path_info[0]) {
--- 228,238 ----
      if (!r->path_info || !*r->path_info || !strcmp (r->protocol, "INCLUDED")) {
          table_set (e, "SCRIPT_NAME", r->uri);
      } else {
! 	int path_info_start = find_path_info (r->uri, r->path_info);
! 
! 	table_set (e, "SCRIPT_NAME", pstrndup(r->pool, r->uri,
! 					      path_info_start));
! 	table_set (e, "PATH_INFO", r->uri + path_info_start);
      }
  	
      if (r->path_info && r->path_info[0]) {
***************
*** 227,234 ****
  	request_rec *pa_req = sub_req_lookup_uri(
  				    escape_uri(r->pool, r->path_info), r);
        
-         table_set (e, "PATH_INFO", r->path_info);
- 
  	/* Don't bother destroying pa_req --- it's only created in
  	 * child processes which are about to jettison their address
  	 * space anyway.  BTW, we concatenate filename and path_info
--- 244,249 ----


-- Alexei Kosut <akosut@organic.com>            The Apache HTTP Server 
   http://www.nueva.pvt.k12.ca.us/~akosut/      http://www.apache.org/




Mime
View raw message