]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Fix spaces handling in proc/self/mountinfo.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 12 Nov 2011 22:14:51 +0000 (23:14 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 12 Nov 2011 22:14:51 +0000 (23:14 +0100)
* util/getroot.c (unescape): New function.
(grub_find_root_device_from_mountinfo): Use unescape.

ChangeLog
util/getroot.c

index c12f19951685c0d65e1f06ca7beb635e005521df..ab253ddfd764313ddb2e04285f40153b39b3b469 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-11-12  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Fix spaces handling in proc/self/mountinfo.
+
+       * util/getroot.c (unescape): New function.
+       (grub_find_root_device_from_mountinfo): Use unescape.
+
 2011-11-12  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Support ZFS embedding.
index f5d6d3f624ad1af4ea9ac905ac64c786da6c49e9..96879f545882340a43aa18527a32ac46bfdfbb8b 100644 (file)
@@ -129,6 +129,27 @@ struct mountinfo_entry
    can't deal with the multiple-device case yet, but in the meantime, we can
    at least cope with the single-device case by scanning
    /proc/self/mountinfo.  */
+static void
+unescape (char *str)
+{
+  char *optr;
+  const char *iptr;
+  for (iptr = optr = str; *iptr; optr++)
+    {
+      if (iptr[0] == '\\' && iptr[1] >= '0' && iptr[1] < '8'
+         && iptr[2] >= '0' && iptr[2] < '8'
+         && iptr[3] >= '0' && iptr[3] < '8')
+       {
+         *optr = (((iptr[1] - '0') << 6) | ((iptr[2] - '0') << 3)
+                  | (iptr[3] - '0'));
+         iptr += 4;
+       }
+      else
+       *optr = *iptr++;
+    }
+  *optr = 0;
+}
+
 char *
 grub_find_root_device_from_mountinfo (const char *dir, char **relroot)
 {
@@ -165,6 +186,9 @@ grub_find_root_device_from_mountinfo (const char *dir, char **relroot)
                  entry.enc_root, entry.enc_path, &count) < 6)
        continue;
 
+      unescape (entry.enc_root);
+      unescape (entry.enc_path);
+
       enc_path_len = strlen (entry.enc_path);
       /* Check that enc_path is a prefix of dir.  The prefix must either be
          the entire string, or end with a slash, or be immediately followed