Blame SOURCES/0240-Clean-up-some-errors-in-the-linuxefi-loader.patch

d41074
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a85e8e
From: Peter Jones <pjones@redhat.com>
a85e8e
Date: Wed, 24 May 2017 15:58:18 -0400
d41074
Subject: [PATCH] Clean up some errors in the linuxefi loader
a85e8e
a85e8e
Signed-off-by: Peter Jones <pjones@redhat.com>
a85e8e
---
d41074
 grub-core/loader/i386/efi/linux.c | 16 ++++++++--------
d41074
 1 file changed, 8 insertions(+), 8 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
d41074
index c123afad19c..7166ec17f8f 100644
a85e8e
--- a/grub-core/loader/i386/efi/linux.c
a85e8e
+++ b/grub-core/loader/i386/efi/linux.c
a85e8e
@@ -161,8 +161,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
a85e8e
 		int argc, char *argv[])
a85e8e
 {
a85e8e
   grub_file_t file = 0;
a85e8e
-  struct linux_kernel_header *lh;
a85e8e
-  grub_ssize_t len, start, filelen;
a85e8e
+  struct linux_kernel_header *lh = NULL;
a85e8e
+  grub_ssize_t start, filelen;
a85e8e
   void *kernel = NULL;
a85e8e
   int setup_header_end_offset;
a85e8e
   int rc;
a85e8e
@@ -212,18 +212,19 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
a85e8e
       goto fail;
a85e8e
     }
a85e8e
 
a85e8e
-  grub_dprintf ("linuxefi", "params = %p\n", (unsigned long) params);
a85e8e
+  grub_dprintf ("linuxefi", "params = %p\n", params);
a85e8e
 
a85e8e
   grub_memset (params, 0, sizeof(*params));
a85e8e
 
a85e8e
   setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
d41074
   grub_dprintf ("linuxefi", "copying %lu bytes from %p to %p\n",
a85e8e
-		MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1,
a85e8e
+		MIN((grub_size_t)0x202+setup_header_end_offset,
a85e8e
+		    sizeof (*params)) - 0x1f1,
a85e8e
 		(grub_uint8_t *)kernel + 0x1f1,
a85e8e
 		(grub_uint8_t *)params + 0x1f1);
a85e8e
   grub_memcpy ((grub_uint8_t *)params + 0x1f1,
a85e8e
 	       (grub_uint8_t *)kernel + 0x1f1,
a85e8e
-		MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
a85e8e
+		MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
a85e8e
   lh = (struct linux_kernel_header *)params;
a85e8e
   grub_dprintf ("linuxefi", "lh is at %p\n", lh);
a85e8e
   grub_dprintf ("linuxefi", "checking lh->boot_flag\n");
a85e8e
@@ -254,7 +255,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
a85e8e
       goto fail;
a85e8e
     }
a85e8e
 
a85e8e
-#ifdef defined(__x86_64__) || defined(__aarch64__)
a85e8e
+#if defined(__x86_64__) || defined(__aarch64__)
a85e8e
   grub_dprintf ("linuxefi", "checking lh->xloadflags\n");
a85e8e
   if (!(lh->xloadflags & LINUX_XLF_KERNEL_64))
a85e8e
     {
d41074
@@ -298,7 +299,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
a85e8e
   handover_offset = lh->handover_offset;
a85e8e
 
a85e8e
   start = (lh->setup_sects + 1) * 512;
a85e8e
-  len = grub_file_size(file) - start;
a85e8e
 
a85e8e
   kernel_mem = grub_efi_allocate_pages(lh->pref_address,
a85e8e
 				       BYTES_TO_PAGES(lh->init_size));
d41074
@@ -344,7 +344,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
a85e8e
       loaded = 0;
a85e8e
     }
a85e8e
 
a85e8e
-  if (linux_cmdline && !loaded)
a85e8e
+  if (linux_cmdline && lh && !loaded)
a85e8e
     grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
a85e8e
 			 linux_cmdline,
a85e8e
 			 BYTES_TO_PAGES(lh->cmdline_size + 1));