]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo):
authorColin Watson <cjwatson@ubuntu.com>
Thu, 6 Jan 2011 11:09:17 +0000 (11:09 +0000)
committerColin Watson <cjwatson@ubuntu.com>
Thu, 6 Jan 2011 11:09:17 +0000 (11:09 +0000)
Fix prefix check to handle the case where dir ends with a slash
(most significantly, "/" itself).
Reported by: Michael Vogt.

ChangeLog
grub-core/kern/emu/getroot.c

index 0159aab3d6e9bfc0a599839df1457a60d0d2adaf..a6d62da6cfb848239e932b3d440d8da1c89a2a79 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-01-06  Colin Watson  <cjwatson@ubuntu.com>
+
+       * grub-core/kern/emu/getroot.c (find_root_device_from_mountinfo):
+       Fix prefix check to handle the case where dir ends with a slash
+       (most significantly, "/" itself).
+       Reported by: Michael Vogt.
+
 2011-01-05  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Run terminfo_cls on initing terminfo output to clear the screen and
index 5356685e978a7ea79f027bf344d758252a782edb..aedef9e0e02756bc9b7cefc3601ddf1537bd3212 100644 (file)
@@ -135,8 +135,12 @@ find_root_device_from_mountinfo (const char *dir)
        continue; /* only a subtree is mounted */
 
       enc_path_len = strlen (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
+         by a slash.  */
       if (strncmp (dir, enc_path, enc_path_len) != 0 ||
-         (dir[enc_path_len] && dir[enc_path_len] != '/'))
+         (enc_path_len && dir[enc_path_len - 1] != '/' &&
+          dir[enc_path_len] && dir[enc_path_len] != '/'))
        continue;
 
       /* This is a parent of the requested directory.  /proc/self/mountinfo