canonicalize, canonicalize-lgpl: Microsoft Windows prefix fixes
authorEli Zaretskii <eliz@gnu.org>
Mon, 10 Dec 2012 22:52:22 +0000 (14:52 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 10 Dec 2012 22:52:43 +0000 (14:52 -0800)
* lib/canonicalize.c (canonicalize_filename_mode):
* lib/canonicalize-lgpl.c (__realpath): Recompute prefix_len after
fetching the current directory.  Don't overrun the beginning of
rpath if there's no slashes after the MS-Windows drive letter.

ChangeLog
lib/canonicalize-lgpl.c
lib/canonicalize.c

index 413e435..a49fc07 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-12-10  Eli Zaretskii  <eliz@gnu.org>
+
+       canonicalize, canonicalize-lgpl: Microsoft Windows prefix fixes
+       * lib/canonicalize.c (canonicalize_filename_mode):
+       * lib/canonicalize-lgpl.c (__realpath): Recompute prefix_len after
+       fetching the current directory.  Don't overrun the beginning of
+       rpath if there's no slashes after the MS-Windows drive letter.
+
 2012-12-08  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        maint.mk: avoid extra forks
index 0888501..6d26fa6 100644 (file)
@@ -157,6 +157,8 @@ __realpath (const char *name, char *resolved)
           goto error;
         }
       dest = strchr (rpath, '\0');
+      start = name;
+      prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath);
     }
   else
     {
@@ -173,9 +175,10 @@ __realpath (const char *name, char *resolved)
             *dest++ = '/';
           *dest = '\0';
         }
+      start = name + prefix_len;
     }
 
-  for (start = end = name + prefix_len; *start; start = end)
+  for (end = start; *start; start = end)
     {
 #ifdef _LIBC
       struct stat64 st;
@@ -200,7 +203,7 @@ __realpath (const char *name, char *resolved)
         {
           /* Back up to previous component, ignore if at root already.  */
           if (dest > rpath + prefix_len + 1)
-            for (--dest; !ISSLASH (dest[-1]); --dest)
+            for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
               continue;
           if (DOUBLE_SLASH_IS_DISTINCT_ROOT
               && dest == rpath + 1 && !prefix_len
@@ -334,7 +337,7 @@ __realpath (const char *name, char *resolved)
                   /* Back up to previous component, ignore if at root
                      already: */
                   if (dest > rpath + prefix_len + 1)
-                    for (--dest; !ISSLASH (dest[-1]); --dest)
+                    for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
                       continue;
                   if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
                       && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
index 33ad29f..176e55f 100644 (file)
@@ -150,6 +150,8 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
         {
           rname_limit = dest;
         }
+      start = name;
+      prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);
     }
   else
     {
@@ -168,9 +170,10 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
             *dest++ = '/';
           *dest = '\0';
         }
+      start = name + prefix_len;
     }
 
-  for (start = name + prefix_len; *start; start = end)
+  for ( ; *start; start = end)
     {
       /* Skip sequence of multiple file name separators.  */
       while (ISSLASH (*start))
@@ -188,7 +191,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
         {
           /* Back up to previous component, ignore if at root already.  */
           if (dest > rname + prefix_len + 1)
-            for (--dest; !ISSLASH (dest[-1]); --dest)
+            for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
               continue;
           if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1
               && !prefix_len && ISSLASH (*dest) && !ISSLASH (dest[1]))
@@ -308,7 +311,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
                   /* Back up to previous component, ignore if at root
                      already: */
                   if (dest > rname + prefix_len + 1)
-                    for (--dest; !ISSLASH (dest[-1]); --dest)
+                    for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
                       continue;
                   if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1
                       && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)