]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* util/hostdisk.c (make_device_name): Fix buffer length
authordavem <davem@localhost>
Tue, 14 Apr 2009 09:07:25 +0000 (09:07 +0000)
committerdavem <davem@localhost>
Tue, 14 Apr 2009 09:07:25 +0000 (09:07 +0000)
calculations.

ChangeLog
util/hostdisk.c

index 28657554ddca3e3821eb530ba9db0d3b0055db38..9c51eefe15bf367790501d0202e052dd3d4af98b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-04-14  John Stanley <jpsinthemix@verizon.net>
+           David S. Miller  <davem@davemloft.net>
+
+       * util/hostdisk.c (make_device_name): Fix buffer length
+       calculations.
+
 2009-04-14  Felix Zielcke  <fzielcke@z-51.de>
 
        * util/hostdisk.c [__FreeBSD__ || __FreeBSD_kernel__]: Include
index 1825ac07b0f61c11c788ef4eeffa4acd5975e5fc..2fd1010a25ca3837cf2e1f8116cc7362f76ae3eb 100644 (file)
@@ -656,11 +656,21 @@ make_device_name (int drive, int dos_part, int bsd_part)
   char *p;
 
   if (dos_part >= 0)
-    len += 1 + ((dos_part + 1) / 10);
+    {
+      /* Add in char length of dos_part+1 */
+      int tmp = dos_part + 1;
+      len++;
+      while ((tmp /= 10) != 0)
+       len++;
+    }
   if (bsd_part >= 0)
     len += 2;
 
-  p = xmalloc (len);
+  /* Length to alloc is: char length of map[drive].drive, plus
+   *                     char length of (dos_part+1) or of bsd_part, plus
+   *                     2 for the comma and a null/end of string (\0)
+   */
+  p = xmalloc (len + 2);
   sprintf (p, "%s", map[drive].drive);
   
   if (dos_part >= 0)