]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2010-01-20 Felix Zielcke <fzielcke@z-51.de>
authorFelix Zielcke <fzielcke@z-51.de>
Wed, 20 Jan 2010 22:53:53 +0000 (23:53 +0100)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 20 Jan 2010 22:53:53 +0000 (23:53 +0100)
* util/misc.c (make_system_path_relative_to_its_root): Change the work
around for handling "/" to the correct fix.  Fix a memory leak.  Use
xstrdup instead of strdup.

ChangeLog
util/misc.c

index 64aa9d593e2105128c95b55be7b5caf6e13a5062..e69ead80dad1bcf0e07e03a89798811745f83a6d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-01-20  Felix Zielcke <fzielcke@z-51.de>
+
+       * util/misc.c (make_system_path_relative_to_its_root): Change the work
+       around for handling "/" to the correct fix.  Fix a memory leak.  Use
+       xstrdup instead of strdup.
+
 2010-01-20  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * conf/mips.rmk (kernel_img_HEADERS): Add env_private.h
index c5ab62e42c131ab52d186f709ec4549ec5055456..b4960087e8b6a05c8632aa95c45bc8f3f8d67e52 100644 (file)
@@ -513,13 +513,13 @@ make_system_path_relative_to_its_root (const char *path)
     grub_util_error ("failed to get canonical path of %s", path);
 
   len = strlen (p) + 1;
-  buf = strdup (p);
+  buf = xstrdup (p);
   free (p);
 
   if (stat (buf, &st) < 0)
     grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
 
-  buf2 = strdup (buf);
+  buf2 = xstrdup (buf);
   num = st.st_dev;
 
   /* This loop sets offset to the number of chars of the root
@@ -541,12 +541,16 @@ make_system_path_relative_to_its_root (const char *path)
       /* buf is another filesystem; we found it.  */
       if (st.st_dev != num)
        {
-         /* offset == 0 means path given is the mount point.  */
+         /* offset == 0 means path given is the mount point.
+            This works around special-casing of "/" in Un*x.  This function never
+            prints trailing slashes (so that its output can be appended a slash
+            unconditionally).  Each slash in is considered a preceding slash, and
+            therefore the root directory is an empty string.  */
          if (offset == 0)
            {
              free (buf);
              free (buf2);
-             return strdup ("/");
+             return xstrdup ("");
            }
          else
            break;
@@ -563,11 +567,19 @@ make_system_path_relative_to_its_root (const char *path)
              buf2[len - 1] = '\0';
              len--;
            }
-         return buf2;
+         if (len > 1)
+           return buf2;
+         else
+           {
+             /* This means path given is just a backslash.  As above
+                we have to return an empty string.  */
+             free (buf2);
+             return xtrdup ("");
+           }
        }
     }
   free (buf);
-  buf3 = strdup (buf2 + offset);
+  buf3 = xstrdup (buf2 + offset);
   free (buf2);
 
   len = strlen (buf3);
@@ -577,13 +589,6 @@ make_system_path_relative_to_its_root (const char *path)
       len--;
     }
 
-  /* This works around special-casing of "/" in Un*x.  This function never
-     prints trailing slashes (so that its output can be appended a slash
-     unconditionally).  Each slash in is considered a preceding slash, and
-     therefore the root directory is an empty string.  */
-  if (!strcmp (buf3, "/"))
-    buf3[0] = '\0';
-
   return buf3;
 }