Hello!

This patch fixes lib/device.c to use dynamic allocation for the
device names obtained in get_*_name () functions:

 - the name variable is returned by the functions instead of
   passing by reference, so that they can allocate it themselves.
 - the get_*_name functions use asprintf() to allocate the device
   name dynamicaly.
 - for NetBSD, it still uses static allocation since the "opendisk"
   call is unable (that i know of) to deal with dynamic buffers.

This fix is needed to work for kernels that have device names longer than
16 chars, and for GCS compliance (section 4.1).

-- 
Robert Millan
--- grub.old/lib/device.c       2003-02-17 12:35:30.000000000 +0000
+++ grub/lib/device.c   2003-07-18 15:38:28.000000000 +0000
@@ -186,9 +186,10 @@
 #endif /* __linux__ */
 
 /* These three functions are quite different among OSes.  */
-static void
-get_floppy_disk_name (char *name, int unit)
+static char *
+get_floppy_disk_name (int unit)
 {
+  char *name = malloc (16);
 #if defined(__linux__)
   /* GNU/Linux */
   if (have_devfs ())
@@ -216,11 +217,13 @@
   /* Set NAME to a bogus string.  */
   *name = 0;
 #endif
+  return name;
 }
 
-static void
-get_ide_disk_name (char *name, int unit)
+static char *
+get_ide_disk_name (int unit)
 {
+  char *name = malloc (16);
 #if defined(__linux__)
   /* GNU/Linux */
   sprintf (name, "/dev/hd%c", unit + 'a');
@@ -258,11 +261,13 @@
   /* Set NAME to a bogus string.  */
   *name = 0;
 #endif
+  return name;
 }
 
-static void
-get_scsi_disk_name (char *name, int unit)
+static char *
+get_scsi_disk_name (int unit)
 {
+  char *name = malloc (16);
 #if defined(__linux__)
   /* GNU/Linux */
   sprintf (name, "/dev/sd%c", unit + 'a');
@@ -296,13 +301,16 @@
   /* Set NAME to a bogus string.  */
   *name = 0;
 #endif
+  return name;
 }
 
 #ifdef __linux__
-static void
-get_dac960_disk_name (char *name, int controller, int drive)
+static char *
+get_dac960_disk_name (int controller, int drive)
 {
+  char *name = malloc (24);
   sprintf (name, "/dev/rd/c%dd%d", controller, drive);
+  return name;
 }
 #endif
 
@@ -537,9 +545,9 @@
   /* Floppies.  */
   for (i = 0; i < floppy_disks; i++)
     {
-      char name[16];
-      
-      get_floppy_disk_name (name, i);
+      char *name;
+
+      name = get_floppy_disk_name (i);
       /* In floppies, write the map, whether check_device succeeds
         or not, because the user just does not insert floppies.  */
       if (fp)
@@ -550,6 +558,7 @@
          (*map)[i] = strdup (name);
          assert ((*map)[i]);
        }
+      free (name);
     }
   
 #ifdef __linux__
@@ -592,9 +601,9 @@
   /* IDE disks.  */
   for (i = 0; i < 8; i++)
     {
-      char name[16];
+      char *name;
       
-      get_ide_disk_name (name, i);
+      name = get_ide_disk_name (i);
       if (check_device (name))
        {
          (*map)[num_hd + 0x80] = strdup (name);
@@ -606,14 +615,15 @@
          
          num_hd++;
        }
+      free (name);
     }
   
   /* The rest is SCSI disks.  */
   for (i = 0; i < 16; i++)
     {
-      char name[16];
+      char *name;
       
-      get_scsi_disk_name (name, i);
+      name = get_scsi_disk_name (i);
       if (check_device (name))
        {
          (*map)[num_hd + 0x80] = strdup (name);
@@ -625,6 +635,7 @@
          
          num_hd++;
        }
+      free (name);
     }
   
 #ifdef __linux__
@@ -640,9 +651,9 @@
       {
        for (drive = 0; drive < 15; drive++)
          {
-           char name[24];
+           char *name;
            
-           get_dac960_disk_name (name, controller, drive);
+           name = get_dac960_disk_name (controller, drive);
            if (check_device (name))
              {
                (*map)[num_hd + 0x80] = strdup (name);
@@ -654,6 +665,7 @@
                
                num_hd++;
              }
+           free (name);
          }
       }
   }
_______________________________________________
Bug-grub mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-grub

Reply via email to