You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2006/07/24 07:54:11 UTC

svn commit: r424917 - /apr/apr/branches/0.9.x/file_io/win32/filepath.c

Author: wrowe
Date: Sun Jul 23 22:54:10 2006
New Revision: 424917

URL: http://svn.apache.org/viewvc?rev=424917&view=rev
Log:
  
  Solve svn issue 1869, avoid replacing previous ../ segments when multiple
  ../../.. patterns are present.  This patch also normalizes the .. path
  seperators to use the same rules as normal paths, that is, if it's NATIVE
  use '\' (previous behavior), and (new behavior) if TRUENAME not NATIVE,
  use '/', otherwise the given slash.  Adds no trailing slash if none was
  present on input.  Solved with hints from Lieven Govaerts <lgo mobsol.be>.

  Resolves test fail identified by test/testnames.c commit 424831

Backports: 424915

Modified:
    apr/apr/branches/0.9.x/file_io/win32/filepath.c

Modified: apr/apr/branches/0.9.x/file_io/win32/filepath.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/win32/filepath.c?rev=424917&r1=424916&r2=424917&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/file_io/win32/filepath.c (original)
+++ apr/apr/branches/0.9.x/file_io/win32/filepath.c Sun Jul 23 22:54:10 2006
@@ -677,16 +677,22 @@
                 /* Otherwise this is simply a noop, above root is root.
                  */
             }
-            else if (pathlen == 0 ||
-                     (pathlen >= 3 && (pathlen == 3
-                                    || path[pathlen - 4] == ':')
-                                   &&  path[pathlen - 3] == '.' 
-                                   &&  path[pathlen - 2] == '.' 
-                                   && (path[pathlen - 1] == '/' 
-                                    || path[pathlen - 1] == '\\')))
+            else if (pathlen == 0 
+                      || (pathlen >= 3 
+                           && (pathlen == 3
+                                || path[pathlen - 4] == ':'
+                                || path[pathlen - 4] == '/' 
+                                || path[pathlen - 4] == '\\')
+                           &&  path[pathlen - 3] == '.' 
+                           &&  path[pathlen - 2] == '.' 
+                           && (path[pathlen - 1] == '/' 
+                                || path[pathlen - 1] == '\\')))
             {
-                /* Path is already backpathed or empty, if the
-                 * APR_FILEPATH_SECUREROOTTEST.was given die now.
+                /* Verified path is empty, exactly "..[/\]", or ends
+                 * in "[:/\]..[/\]" - these patterns we will not back
+                 * over since they aren't 'prior segements'.
+                 * 
+                 * If APR_FILEPATH_SECUREROOTTEST.was given, die now.
                  */
                 if (flags & APR_FILEPATH_SECUREROOTTEST)
                     return APR_EABOVEROOT;
@@ -695,9 +701,13 @@
                  */
                 if (pathlen + 3 >= sizeof(path))
                     return APR_ENAMETOOLONG;
-                memcpy(path + pathlen, ((flags & APR_FILEPATH_NATIVE) 
-                                          ? "..\\" : "../"), 3);
-                pathlen += 3;
+                path[pathlen++] = '.';
+                path[pathlen++] = '.';
+                if (addpath[segend]) {
+                    path[pathlen++] = ((flags & APR_FILEPATH_NATIVE) 
+                                    ? '\\' : ((flags & APR_FILEPATH_TRUENAME)
+                                           ? '/' : addpath[segend]));
+                }
                 /* The 'root' part of this path now includes the ../ path,
                  * because that backpath will not be parsed by the truename
                  * code below.