Skip to contentSkip to conversation

strip disk->name of partition suffix in grub_disk_open

PATCH In review Grégoire Sutre 2 participants 3 messages Jul 9, 2010 – Jul 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 strip disk->name of partition suffix in grub_disk_open

Hi,

When the argument passed to grub_disk_open is a string containing a partition, e.g. "hd0,msdos3,bsd7", disk->name is set to the full string instead of just the prefix up to the first ',' (here "hd0"). This leads to incorrect partition identifiers when the disk name and the partition name are concatenated (I observed this in the debug messages of my nested partitions patch).

The attached patch fixes this issue.

Grégoire

=== modified file 'kern/disk.c'

disk.c +7 -2
@@ -248,11 +248,16 @@ grub_disk_open (const char *name)
   if (! disk)
     return 0;
 
-  disk->name = grub_strdup (name);
+  p = find_part_sep (name);
+
+  if (p)
+    disk->name = grub_strndup (name, p - name);
+  else
+    disk->name = grub_strdup (name);
+
   if (! disk->name)
     goto fail;
 
-  p = find_part_sep (name);
   if (p)
     {
       grub_size_t len = p - name;
#1 lore raw
Quoted 8 lines · Grégoire Sutre

Hi,

When the argument passed to grub_disk_open is a string containing a partition, e.g. "hd0,msdos3,bsd7", disk->name is set to the full string instead of just the prefix up to the first ',' (here "hd0"). This leads to incorrect partition identifiers when the disk name and the partition name are concatenated (I observed this in the debug messages of my nested partitions patch).

Which functions concatenate disk->name with anything else? It looks like disk->name is with partitions by design.

Quoted 11 lines

The attached patch fixes this issue.

Grégoire

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#2 lore raw
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko

Which functions concatenate disk->name with anything else? It looks like disk->name is with partitions by design.

In several places, the (full) grub partition name is obtained by concatenating disk->name with the result of grub_partition_get_name.

If I read the code correctly, this is what is done in:

function iterate_partition, file normal/completion.c. function grub_device_iterate, file kern/device.c function grub_efidisk_get_device_name, file disk/efi/efidisk.c

and I did the same in

function grub_util_biosdisk_get_grub_dev, file kern/emu/hostdisk.c

and more recently, for warnings/dprintfs, in

function grub_partition_check_containment, file kern/partition.c function bsdlabel_partition_map_iterate, file partmap/bsdlabel.c

Assuming that the above are correct and that disk->name is correctly set in grub_disk_open (e.g. hd0,msdos3,bsd7), then shouldn't disk->partition have a NULL parent (which is not the case right now)?

Grégoire