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

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