From 63fe43f3c3d3907c10acee68ffef4e8abb21021b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 29 Jan 2012 21:49:44 +0100 Subject: [PATCH] * util/getroot.c (grub_util_get_dm_node_linear_info): Fix memory leak. * grub-core/disk/cryptodisk.c (cryptodisk_cleanup): Disable for now to avoid double free. * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_dev): Rename to hostdisk. * include/grub/disk.h (grub_disk_dev_id): New id HOSTDISK. * util/grub-probe.c (escape_of_path): Always return a new copy. (print_full_name): Escape path. (probe): Don't call grub_util_devname_to_ofpath on NULL. Fix hints on abstractions. --- ChangeLog | 13 +++++++++++++ grub-core/disk/cryptodisk.c | 2 ++ grub-core/kern/emu/hostdisk.c | 4 ++-- include/grub/disk.h | 1 + util/getroot.c | 23 +++++++++++++++++++---- util/grub-probe.c | 35 +++++++++++++++++++++++------------ 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48f453059..943ed0fad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-01-29 Vladimir Serbinenko + + * util/getroot.c (grub_util_get_dm_node_linear_info): Fix memory leak. + * grub-core/disk/cryptodisk.c (cryptodisk_cleanup): Disable for + now to avoid double free. + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_dev): Rename to + hostdisk. + * include/grub/disk.h (grub_disk_dev_id): New id HOSTDISK. + * util/grub-probe.c (escape_of_path): Always return a new copy. + (print_full_name): Escape path. + (probe): Don't call grub_util_devname_to_ofpath on NULL. + Fix hints on abstractions. + 2012-01-29 Vladimir Serbinenko * util/grub-mkconfig_lib.in (prepare_grub_to_access_device): diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 8be2e21cf..7d63f3e46 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -658,6 +658,7 @@ grub_cryptodisk_memberlist (grub_disk_t disk) static void cryptodisk_cleanup (void) { +#if 0 grub_cryptodisk_t dev = cryptodisk_list; grub_cryptodisk_t tmp; @@ -671,6 +672,7 @@ cryptodisk_cleanup (void) grub_free (dev); dev = tmp; } +#endif } grub_err_t diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 1a39e9c56..704911e12 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1107,8 +1107,8 @@ grub_util_biosdisk_close (struct grub_disk *disk) static struct grub_disk_dev grub_util_biosdisk_dev = { - .name = "biosdisk", - .id = GRUB_DISK_DEVICE_BIOSDISK_ID, + .name = "hostdisk", + .id = GRUB_DISK_DEVICE_HOSTDISK_ID, .iterate = grub_util_biosdisk_iterate, .open = grub_util_biosdisk_open, .close = grub_util_biosdisk_close, diff --git a/include/grub/disk.h b/include/grub/disk.h index 27d74788d..ca46f031e 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -40,6 +40,7 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_SCSI_ID, GRUB_DISK_DEVICE_CRYPTODISK_ID, GRUB_DISK_DEVICE_ARCDISK_ID, + GRUB_DISK_DEVICE_HOSTDISK_ID, }; struct grub_disk; diff --git a/util/getroot.c b/util/getroot.c index 6b773767c..cae7611ab 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -1246,33 +1246,48 @@ grub_util_get_dm_node_linear_info (const char *dev, return 0; if (!dm_task_set_name(dmt, dev)) - return 0; + { + dm_task_destroy (dmt); + return 0; + } dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) - return 0; + { + dm_task_destroy (dmt); + return 0; + } next = dm_get_next_target(dmt, next, &start, &length, &target, ¶ms); if (grub_strcmp (target, "linear") != 0) - return 0; + { + dm_task_destroy (dmt); + return 0; + } major = grub_strtoul (params, &ptr, 10); if (grub_errno) { + dm_task_destroy (dmt); grub_errno = GRUB_ERR_NONE; return 0; } if (*ptr != ':') - return 0; + { + dm_task_destroy (dmt); + return 0; + } ptr++; minor = grub_strtoul (ptr, 0, 10); if (grub_errno) { grub_errno = GRUB_ERR_NONE; + dm_task_destroy (dmt); return 0; } if (maj) *maj = major; if (min) *min = minor; + dm_task_destroy (dmt); return 1; } #endif diff --git a/util/grub-probe.c b/util/grub-probe.c index bb75d938c..17edff6ce 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -149,7 +149,7 @@ escape_of_path (const char *orig_path) const char *p; if (!strchr (orig_path, ',')) - return (char *) orig_path; + return (char *) xstrdup (orig_path); new_path = xmalloc (strlen (orig_path) * 2 + sizeof ("ieee1275/")); @@ -259,14 +259,16 @@ guess_baremetal_drive (const char *orig_path) static void print_full_name (const char *drive, grub_device_t dev) { + char *dname = escape_of_path (drive); if (dev->disk->partition) { char *pname = grub_partition_get_name (dev->disk->partition); - printf ("%s,%s", drive, pname); + printf ("%s,%s", dname, pname); free (pname); } else - printf ("%s", drive); + printf ("%s", dname); + free (dname); } static void @@ -363,17 +365,15 @@ probe (const char *path, char *device_name) if (print == PRINT_HINT_STR) { const char *osdev = grub_util_biosdisk_get_osdev (dev->disk); - const char *orig_path = grub_util_devname_to_ofpath (osdev); + const char *ofpath = osdev ? grub_util_devname_to_ofpath (osdev) : 0; char *biosname, *bare, *efi; const char *map; - if (orig_path) + if (ofpath) { - char *ofpath = escape_of_path (orig_path); printf ("--hint-ieee1275='"); print_full_name (ofpath, dev); printf ("' "); - free (ofpath); } biosname = guess_bios_drive (device_name); @@ -417,6 +417,16 @@ probe (const char *path, char *device_name) goto end; } + if ((print == PRINT_COMPATIBILITY_HINT || print == PRINT_BIOS_HINT + || print == PRINT_IEEE1275_HINT || print == PRINT_BAREMETAL_HINT + || print == PRINT_EFI_HINT || print == PRINT_ARC_HINT) + && dev->disk->dev->id != GRUB_DISK_DEVICE_HOSTDISK_ID) + { + print_full_name (dev->disk->name, dev); + printf ("\n"); + goto end; + } + if (print == PRINT_COMPATIBILITY_HINT) { const char *map; @@ -449,8 +459,7 @@ probe (const char *path, char *device_name) if (print == PRINT_IEEE1275_HINT) { const char *osdev = grub_util_biosdisk_get_osdev (dev->disk); - const char *orig_path = grub_util_devname_to_ofpath (osdev); - char *ofpath = escape_of_path (orig_path); + const char *ofpath = grub_util_devname_to_ofpath (osdev); const char *map; map = grub_util_biosdisk_get_compatibility_hint (dev->disk); @@ -460,11 +469,13 @@ probe (const char *path, char *device_name) print_full_name (map, dev); } - printf (" "); - print_full_name (ofpath, dev); + if (ofpath) + { + printf (" "); + print_full_name (ofpath, dev); + } printf ("\n"); - free (ofpath); goto end; } if (print == PRINT_EFI_HINT)