Blob Blame History Raw
From 444dd65bf9b5655afd4a32d71fa9d22a5b46caa2 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 24 May 2017 15:58:18 -0400
Subject: [PATCH 240/260] Clean up some errors in the linuxefi loader

Signed-off-by: Peter Jones <pjones@redhat.com>
---
 grub-core/loader/i386/efi/linux.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
index 52dc71903..19950d2f2 100644
--- a/grub-core/loader/i386/efi/linux.c
+++ b/grub-core/loader/i386/efi/linux.c
@@ -161,8 +161,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 		int argc, char *argv[])
 {
   grub_file_t file = 0;
-  struct linux_kernel_header *lh;
-  grub_ssize_t len, start, filelen;
+  struct linux_kernel_header *lh = NULL;
+  grub_ssize_t start, filelen;
   void *kernel = NULL;
   int setup_header_end_offset;
   int rc;
@@ -212,18 +212,19 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-  grub_dprintf ("linuxefi", "params = %p\n", (unsigned long) params);
+  grub_dprintf ("linuxefi", "params = %p\n", params);
 
   grub_memset (params, 0, sizeof(*params));
 
   setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
-  grub_dprintf ("linuxefi", "copying %d bytes from %p to %p\n",
-		MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1,
+  grub_dprintf ("linuxefi", "copying %zu bytes from %p to %p\n",
+		MIN((grub_size_t)0x202+setup_header_end_offset,
+		    sizeof (*params)) - 0x1f1,
 		(grub_uint8_t *)kernel + 0x1f1,
 		(grub_uint8_t *)params + 0x1f1);
   grub_memcpy ((grub_uint8_t *)params + 0x1f1,
 	       (grub_uint8_t *)kernel + 0x1f1,
-		MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
+		MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
   lh = (struct linux_kernel_header *)params;
   grub_dprintf ("linuxefi", "lh is at %p\n", lh);
   grub_dprintf ("linuxefi", "checking lh->boot_flag\n");
@@ -254,7 +255,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-#ifdef defined(__x86_64__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__aarch64__)
   grub_dprintf ("linuxefi", "checking lh->xloadflags\n");
   if (!(lh->xloadflags & LINUX_XLF_KERNEL_64))
     {
@@ -297,7 +298,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   handover_offset = lh->handover_offset;
 
   start = (lh->setup_sects + 1) * 512;
-  len = grub_file_size(file) - start;
 
   kernel_mem = grub_efi_allocate_pages(lh->pref_address,
 				       BYTES_TO_PAGES(lh->init_size));
@@ -343,7 +343,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       loaded = 0;
     }
 
-  if (linux_cmdline && !loaded)
+  if (linux_cmdline && lh && !loaded)
     grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
 			 linux_cmdline,
 			 BYTES_TO_PAGES(lh->cmdline_size + 1));
-- 
2.13.0