Blame SOURCES/0197-loader-linux-do-not-pad-initrd-with-zeroes-at-the-en.patch

f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Andrei Borzenkov <arvidjaar@gmail.com>
f725e3
Date: Thu, 7 May 2015 20:24:24 +0300
f725e3
Subject: [PATCH] loader/linux: do not pad initrd with zeroes at the end
f725e3
f725e3
Syslinux memdisk is using initrd image and needs to know uncompressed
f725e3
size in advance. For gzip uncompressed size is at the end of compressed
f725e3
stream. Grub padded each input file to 4 bytes at the end, which means
f725e3
syslinux got wrong size.
f725e3
f725e3
Linux initramfs loader apparently does not care about trailing alignment.
f725e3
So change code to align beginning of each file instead which atomatically
f725e3
gives us the correct size for single file.
f725e3
f725e3
Reported-By: David Shaw <dshaw@jabberwocky.com>
f725e3
f725e3
(cherry picked from commit a8c473288d3f0a5e17a903a5121dea1a695dda3b)
f725e3
f725e3
Resolves: rhbz#1219864
f725e3
---
f725e3
 grub-core/loader/linux.c | 11 +++++++----
f725e3
 1 file changed, 7 insertions(+), 4 deletions(-)
f725e3
f725e3
diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
f725e3
index 117232f0c95..d2cd591f604 100644
f725e3
--- a/grub-core/loader/linux.c
f725e3
+++ b/grub-core/loader/linux.c
f725e3
@@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[],
f725e3
   for (i = 0; i < argc; i++)
f725e3
     {
f725e3
       const char *fname = argv[i];
f725e3
+
f725e3
+      initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
f725e3
+
f725e3
       if (grub_memcmp (argv[i], "newc:", 5) == 0)
f725e3
 	{
f725e3
 	  const char *ptr, *eptr;
f725e3
@@ -205,7 +208,7 @@ grub_initrd_init (int argc, char *argv[],
f725e3
       initrd_ctx->nfiles++;
f725e3
       initrd_ctx->components[i].size
f725e3
 	= grub_file_size (initrd_ctx->components[i].file);
f725e3
-      initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
f725e3
+      initrd_ctx->size += initrd_ctx->components[i].size;
f725e3
     }
f725e3
 
f725e3
   if (newc)
f725e3
@@ -248,10 +251,12 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
f725e3
   int i;
f725e3
   int newc = 0;
f725e3
   struct dir *root = 0;
f725e3
+  grub_ssize_t cursize = 0;
f725e3
 
f725e3
   for (i = 0; i < initrd_ctx->nfiles; i++)
f725e3
     {
f725e3
-      grub_ssize_t cursize;
f725e3
+      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
f725e3
+      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
f725e3
 
f725e3
       if (initrd_ctx->components[i].newc_name)
f725e3
 	{
f725e3
@@ -283,8 +288,6 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
f725e3
 	  return grub_errno;
f725e3
 	}
f725e3
       ptr += cursize;
f725e3
-      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
f725e3
-      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
f725e3
     }
f725e3
   if (newc)
f725e3
     ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0);