dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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