httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: apache-1.3/src/modules/standard mod_rewrite.c
Date Wed, 02 Apr 2003 21:11:42 GMT
nd          2003/04/02 13:11:42

  Modified:    src      CHANGES
               src/modules/standard mod_rewrite.c
  Log:
  Fix the misunderstandings between local URL paths and local
  system paths. Note that mod_rewrite handles _both_.
  Fixed also some comments to make the explanations more clear.
  
  PR: 12902
  Obtained from: 2.1 (r1.144)
  Reviewed by: Brad Nicholes, Will Rowe
  
  Revision  Changes    Path
  1.1885    +4 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1884
  retrieving revision 1.1885
  diff -u -r1.1884 -r1.1885
  --- CHANGES	19 Mar 2003 14:01:05 -0000	1.1884
  +++ CHANGES	2 Apr 2003 21:11:40 -0000	1.1885
  @@ -1,5 +1,9 @@
   Changes with Apache 1.3.28
   
  +  *) Fix path handling of mod_rewrite, especially on non-unix systems.
  +     There was some confusion between local paths and URL paths.
  +     PR 12902.  [André Malo]
  +
     *) backport from 2.x series: Prevent endless loops of internal redirects
        in mod_rewrite by aborting after exceeding a limit of internal redirects.
        The limit defaults to 10 and can be changed using the RewriteOptions
  
  
  
  1.186     +43 -12    apache-1.3/src/modules/standard/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
  retrieving revision 1.185
  retrieving revision 1.186
  diff -u -r1.185 -r1.186
  --- mod_rewrite.c	2 Apr 2003 21:01:09 -0000	1.185
  +++ mod_rewrite.c	2 Apr 2003 21:11:41 -0000	1.186
  @@ -1245,8 +1245,11 @@
   #endif
               rewritelog(r, 2, "local path result: %s", r->filename);
   
  -            /* the filename has to start with a slash! */
  -            if (!ap_os_is_path_absolute(r->filename)) {
  +            /* the filename must be either an absolute local path or an
  +             * absolute local URL.
  +             */
  +            if (   *r->filename != '/'
  +                && !ap_os_is_path_absolute(r->filename)) {
                   return BAD_REQUEST;
               }
   
  @@ -1441,14 +1444,39 @@
                       ;
                   /* skip '://' */
                   cp += 3;
  -                if ((cp = strchr(cp, '/')) != NULL) {
  +                if ((cp = strchr(cp, '/')) != NULL && *(++cp)) {
                       rewritelog(r, 2,
                                  "[per-dir %s] trying to replace "
                                  "prefix %s with %s",
                                  dconf->directory, dconf->directory,
                                  dconf->baseurl);
  -                    cp2 = subst_prefix_path(r, cp, dconf->directory,
  -                                            dconf->baseurl);
  +
  +                    /* I think, that hack needs an explanation:
  +                     * well, here is it:
  +                     * mod_rewrite was written for unix systems, were
  +                     * absolute file-system paths start with a slash.
  +                     * URL-paths _also_ start with slashes, so they
  +                     * can be easily compared with system paths.
  +                     *
  +                     * the following assumes, that the actual url-path
  +                     * may be prefixed by the current directory path and
  +                     * tries to replace the system path with the RewriteBase
  +                     * URL.
  +                     * That assumption is true if we use a RewriteRule like
  +                     *
  +                     * RewriteRule ^foo bar [R]
  +                     *
  +                     * (see apply_rewrite_rule function)
  +                     * However on systems that don't have a / as system
  +                     * root this will never match, so we skip the / after the
  +                     * hostname and compare/substitute only the stuff after it.
  +                     *
  +                     * (note that cp was already increased to the right value)
  +                     */
  +                    cp2 = subst_prefix_path(r, cp, (*dconf->directory == '/')
  +                                                   ? dconf->directory + 1
  +                                                   : dconf->directory,
  +                                            dconf->baseurl + 1);
                       if (strcmp(cp2, cp) != 0) {
                           *cp = '\0';
                           r->filename = ap_pstrcat(r->pool, r->filename,
  @@ -1530,8 +1558,11 @@
                   r->filename = ap_pstrdup(r->pool, r->filename+12);
               }
   
  -            /* the filename has to start with a slash! */
  -            if (!ap_os_is_path_absolute(r->filename)) {
  +            /* the filename must be either an absolute local path or an
  +             * absolute local URL.
  +             */
  +            if (   *r->filename != '/'
  +                && !ap_os_is_path_absolute(r->filename)) {
                   return BAD_REQUEST;
               }
   
  @@ -2067,12 +2098,12 @@
       splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND);
   
       /*
  -     *   Again add the previously stripped per-directory location
  -     *   prefix if the new URI is not a new one for this
  -     *   location, i.e. if it's not starting with either a slash
  -     *   or a fully qualified URL scheme.
  +     *  Add the previously stripped per-directory location
  +     *  prefix if the new URI is not a new one for this
  +     *  location, i.e. if it's not an absolute URL (!) path nor
  +     *  a fully qualified URL scheme.
        */
  -    if (prefixstrip && !ap_os_is_path_absolute(r->filename)
  +    if (prefixstrip && *r->filename != '/'
   	&& !is_absolute_uri(r->filename)) {
           rewritelog(r, 3, "[per-dir %s] add per-dir prefix: %s -> %s%s",
                      perdir, r->filename, perdir, r->filename);
  
  
  

Mime
View raw message