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