changeset 17203:60ac4a074708

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.
author Eli Zaretskii <eliz@gnu.org>
date Mon, 10 Dec 2012 14:52:22 -0800
parents 5b730fea4cab
children 69d4aaeb9067
files ChangeLog lib/canonicalize-lgpl.c lib/canonicalize.c
diffstat 3 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -157,6 +157,8 @@
           goto error;
         }
       dest = strchr (rpath, '\0');
+      start = name;
+      prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath);
     }
   else
     {
@@ -173,9 +175,10 @@
             *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 @@
         {
           /* 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 @@
                   /* 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)
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -150,6 +150,8 @@
         {
           rname_limit = dest;
         }
+      start = name;
+      prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);
     }
   else
     {
@@ -168,9 +170,10 @@
             *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 @@
         {
           /* 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 @@
                   /* 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)