diff --git a/ChangeLog b/ChangeLog index 31020644e..9162f2bdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-07-05 Colin Watson + + * util/i386/pc/grub-setup.c (setup): Rename prefix to + install_prefix, in line with install_dos_part and install_bsd_part. + Add new prefix variable, which is copied to install_prefix after + comparing core.img in memory with the one read from disk in the + no-embedding case, and use that rather than overwriting + install_prefix immediately when installing to a partition. + Fixes Debian bug #586621; based on patches by Matt Kraai and M. Vefa + Bicakci. + 2010-07-04 Grégoire Sutre * configure.ac: Avoid == in test command, it's not portable. diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 3fe7d5622..8b2f52bb4 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -102,7 +102,8 @@ setup (const char *dir, struct grub_boot_blocklist *first_block, *block; grub_int32_t *install_dos_part, *install_bsd_part; grub_int32_t dos_part, bsd_part; - char *prefix; + char *install_prefix; + char *prefix = NULL; char *tmp_img; int i; grub_disk_addr_t first_sector; @@ -234,8 +235,8 @@ setup (const char *dir, + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART); install_bsd_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART); - prefix = (char *) (core_img + GRUB_DISK_SECTOR_SIZE + - GRUB_KERNEL_MACHINE_PREFIX); + install_prefix = (char *) (core_img + GRUB_DISK_SECTOR_SIZE + + GRUB_KERNEL_MACHINE_PREFIX); /* Open the root device and the destination device. */ root_dev = grub_device_open (root); @@ -312,15 +313,13 @@ setup (const char *dir, bsd_part = -1; } - if (prefix[0] != '(') + if (install_prefix[0] != '(') { - char *root_part_name, *new_prefix; + char *root_part_name; root_part_name = grub_partition_get_name (root_dev->disk->partition); - new_prefix = xasprintf ("(,%s)%s", root_part_name, prefix); - strcpy (prefix, new_prefix); - free (new_prefix); + prefix = xasprintf ("(,%s)%s", root_part_name, install_prefix); free (root_part_name); } } @@ -411,6 +410,8 @@ setup (const char *dir, *install_dos_part = grub_cpu_to_le32 (dos_part); *install_bsd_part = grub_cpu_to_le32 (bsd_part); + if (prefix) + strcpy (install_prefix, prefix); /* The first blocklist contains the whole sectors. */ first_block->start = grub_cpu_to_le64 (embed_region.start + 1); @@ -571,6 +572,8 @@ unable_to_embed: *install_dos_part = grub_cpu_to_le32 (dos_part); *install_bsd_part = grub_cpu_to_le32 (bsd_part); + if (prefix) + strcpy (install_prefix, prefix); /* Write the first two sectors of the core image onto the disk. */ grub_util_info ("opening the core image `%s'", core_path); @@ -590,6 +593,7 @@ unable_to_embed: /* Sync is a Good Thing. */ sync (); + free (prefix); free (core_path); free (core_img); free (boot_img);