From 6dc333777405df4385dfe8ce99ee1c58baf00436 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sat, 14 Dec 2013 22:04:02 +0100 Subject: [PATCH] Fix definition of grub_efi_hard_drive_device_path. Take care that existing code would work even if by some reason bogus definition is used by EFI implementations. --- ChangeLog | 6 ++++++ grub-core/disk/efi/efidisk.c | 30 +++++++++++++++--------------- grub-core/kern/efi/efi.c | 2 +- include/grub/efi/api.h | 4 ++-- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8ffc725e..d28ca02d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-12-14 Vladimir Serbinenko + + Fix definition of grub_efi_hard_drive_device_path. Take care that + existing code would work even if by some reason bogus definition is + used by EFI implementations. + 2013-12-14 Vladimir Serbinenko * grub-core/osdep/windows/hostdisk.c: Fix cygwin compilation. diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 68f6d9f75..e04203fe0 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -666,20 +666,20 @@ grub_efidisk_get_device_handle (grub_disk_t disk) devices = make_devices (); FOR_CHILDREN (c, devices) { - grub_efi_hard_drive_device_path_t hd; + grub_efi_hard_drive_device_path_t *hd; - grub_memcpy (&hd, c->last_device_path, sizeof (hd)); + hd = (grub_efi_hard_drive_device_path_t *) c->last_device_path; if ((GRUB_EFI_DEVICE_PATH_TYPE (c->last_device_path) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE) && (GRUB_EFI_DEVICE_PATH_SUBTYPE (c->last_device_path) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE) && (grub_partition_get_start (disk->partition) - == (hd.partition_start << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS))) + == (hd->partition_start << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS))) && (grub_partition_get_len (disk->partition) - == (hd.partition_size << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS)))) + == (hd->partition_size << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)))) { handle = c->handle; break; @@ -745,7 +745,7 @@ get_diskname_from_path (const grub_efi_device_path_t *path, struct grub_efidisk_get_device_name_ctx { char *partition_name; - grub_efi_hard_drive_device_path_t hd; + grub_efi_hard_drive_device_path_t *hd; }; /* Helper for grub_efidisk_get_device_name. @@ -757,11 +757,11 @@ grub_efidisk_get_device_name_iter (grub_disk_t disk, struct grub_efidisk_get_device_name_ctx *ctx = data; if (grub_partition_get_start (part) - == (ctx->hd.partition_start << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS)) + == (ctx->hd->partition_start << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) && grub_partition_get_len (part) - == (ctx->hd.partition_size << (disk->log_sector_size - - GRUB_DISK_SECTOR_BITS))) + == (ctx->hd->partition_size << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS))) { ctx->partition_name = grub_partition_get_name (part); return 1; @@ -831,10 +831,10 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) /* Find a partition which matches the hard drive device path. */ ctx.partition_name = NULL; - grub_memcpy (&ctx.hd, ldp, sizeof (ctx.hd)); - if (ctx.hd.partition_start == 0 - && (ctx.hd.partition_size << (parent->log_sector_size - - GRUB_DISK_SECTOR_BITS)) + ctx.hd = (grub_efi_hard_drive_device_path_t *) ldp; + if (ctx.hd->partition_start == 0 + && (ctx.hd->partition_size << (parent->log_sector_size + - GRUB_DISK_SECTOR_BITS)) == grub_disk_get_size (parent)) { dev_name = grub_strdup (parent->name); diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index 19a57d553..c2a5c32ff 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -704,7 +704,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) (unsigned) hd->partition_signature[5], (unsigned) hd->partition_signature[6], (unsigned) hd->partition_signature[7], - (unsigned) hd->mbr_type, + (unsigned) hd->partmap_type, (unsigned) hd->signature_type); } break; diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 623ef14f9..7b46259f7 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -827,8 +827,8 @@ struct grub_efi_hard_drive_device_path grub_efi_uint32_t partition_number; grub_efi_lba_t partition_start; grub_efi_lba_t partition_size; - grub_efi_uint8_t partition_signature[8]; - grub_efi_uint8_t mbr_type; + grub_efi_uint8_t partition_signature[16]; + grub_efi_uint8_t partmap_type; grub_efi_uint8_t signature_type; } __attribute__ ((packed)); typedef struct grub_efi_hard_drive_device_path grub_efi_hard_drive_device_path_t;