]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
loader/linux: do not pad initrd with zeroes at the end
authorAndrei Borzenkov <arvidjaar@gmail.com>
Thu, 7 May 2015 17:24:24 +0000 (20:24 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Thu, 7 May 2015 17:24:24 +0000 (20:24 +0300)
Syslinux memdisk is using initrd image and needs to know uncompressed
size in advance. For gzip uncompressed size is at the end of compressed
stream. Grub padded each input file to 4 bytes at the end, which means
syslinux got wrong size.

Linux initramfs loader apparently does not care about trailing alignment.
So change code to align beginning of each file instead which atomatically
gives us the correct size for single file.

Reported-By: David Shaw <dshaw@jabberwocky.com>
grub-core/loader/linux.c

index 117232f0c951bd1b24685acc4df107a96d6b2704..d2cd591f60480b0c672329916dbe7e86ed9164e4 100644 (file)
@@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[],
   for (i = 0; i < argc; i++)
     {
       const char *fname = argv[i];
+
+      initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
+
       if (grub_memcmp (argv[i], "newc:", 5) == 0)
        {
          const char *ptr, *eptr;
@@ -205,7 +208,7 @@ grub_initrd_init (int argc, char *argv[],
       initrd_ctx->nfiles++;
       initrd_ctx->components[i].size
        = grub_file_size (initrd_ctx->components[i].file);
-      initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
+      initrd_ctx->size += initrd_ctx->components[i].size;
     }
 
   if (newc)
@@ -248,10 +251,12 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
   int i;
   int newc = 0;
   struct dir *root = 0;
+  grub_ssize_t cursize = 0;
 
   for (i = 0; i < initrd_ctx->nfiles; i++)
     {
-      grub_ssize_t cursize;
+      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
+      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
 
       if (initrd_ctx->components[i].newc_name)
        {
@@ -283,8 +288,6 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
          return grub_errno;
        }
       ptr += cursize;
-      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
-      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
     }
   if (newc)
     ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0);