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

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

diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
index bed5919cab3..6db5d0bf3a0 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");
@@ -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_max(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.15.0