From ba9baabecdadff4c7e6652a4d2cd4534807d1c1b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 11 Oct 2013 16:15:43 +0200 Subject: [PATCH] * util/grub-setup.c (setup): Move copying of partition table as futher up as possible to avoid possible overwrite by floppy routines. --- ChangeLog | 7 ++++++- util/grub-setup.c | 18 +++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0c6d6348..087d256c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2013-10-10 Vladimir Serbinenko +2013-10-11 Vladimir Serbinenko + + * util/grub-setup.c (setup): Move copying of partition table as + futher up as possible to avoid possible overwrite by floppy routines. + +2013-10-11 Vladimir Serbinenko * grub-core/fs/fat.c: Fix handling of exfat contiguous files. diff --git a/util/grub-setup.c b/util/grub-setup.c index e65c7ceed..3cbe81f13 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -396,6 +396,15 @@ setup (const char *dir, grub_partition_iterate (dest_dev->disk, identify_partmap, &ctx); + /* Copy the partition table. */ + if (ctx.dest_partmap || + (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))) + memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, + tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, + GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC); + + free (tmp_img); + if (ctx.container && grub_strcmp (ctx.container->partmap->name, "msdos") == 0 && ctx.dest_partmap @@ -450,15 +459,6 @@ setup (const char *dir, } - /* Copy the partition table. */ - if (ctx.dest_partmap || - (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))) - memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, - tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, - GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC); - - free (tmp_img); - if (! ctx.dest_partmap && ! fs && !is_ldm) { grub_util_warn ("%s", _("Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea."));