]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* kern/emu/getroot.c (find_root_device_from_mountinfo): Use getline instead
authorColin Watson <cjwatson@ubuntu.com>
Tue, 1 Jun 2010 17:05:29 +0000 (18:05 +0100)
committerColin Watson <cjwatson@ubuntu.com>
Tue, 1 Jun 2010 17:05:29 +0000 (18:05 +0100)
of fgets into a static buffer.  Use sizeof instead of strlen on a constant
string.  Thanks to Vladimir for review.

ChangeLog.btrfs-probe
kern/emu/getroot.c

index 77c9995c8f3d6339b672d4916b2dd28a4d46b094..c79e6b6a457149929b4571b12a98f604247ff74f 100644 (file)
@@ -1,4 +1,4 @@
-2010-05-18  Colin Watson  <cjwatson@ubuntu.com>
+2010-06-01  Colin Watson  <cjwatson@ubuntu.com>
 
        Add btrfs probing support, currently only in the single-device case.
 
index da62089fa1b5c9f4e218d9565eec327b332d5457..97c24115b20d002493cf867e25acacf4b85cb1f2 100644 (file)
@@ -93,14 +93,15 @@ static char *
 find_root_device_from_mountinfo (const char *dir)
 {
   FILE *fp;
-  char buf[1024];      /* XXX */
+  char *buf = NULL;
+  size_t len = 0;
   char *ret = NULL;
 
   fp = fopen ("/proc/self/mountinfo", "r");
   if (! fp)
     return NULL; /* fall through to other methods */
 
-  while (fgets (buf, sizeof (buf), fp))
+  while (getline (&buf, &len, fp) > 0)
     {
       int mnt_id, parent_mnt_id;
       unsigned int major, minor;
@@ -139,7 +140,7 @@ find_root_device_from_mountinfo (const char *dir)
       if (!sep)
        continue;
 
-      sep += strlen (" - ");
+      sep += sizeof (" - ") - 1;
       if (sscanf (sep, "%s %s", fstype, device) != 2)
        continue;
 
@@ -152,6 +153,7 @@ find_root_device_from_mountinfo (const char *dir)
       ret = strdup (device);
     }
 
+  free (buf);
   fclose (fp);
   return ret;
 }