]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Fix loading of modules of size not divisible by 4
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 12 Dec 2009 01:33:15 +0000 (02:33 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 12 Dec 2009 01:33:15 +0000 (02:33 +0100)
util/grub-mkrawimage.c

index 5399f4c4291eaaf34f8d6a8c28de96f835cdb6ae..58b30f5becb8a83e6330c84afd315237f6bafc63 100644 (file)
@@ -134,7 +134,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
 
   if (config_path)
     {
-      config_size = grub_util_get_image_size (config_path) + 1;
+      config_size = ALIGN_UP(grub_util_get_image_size (config_path) + 1, 4);
       grub_util_info ("the size of config file is 0x%x", config_size);
       total_module_size += config_size + sizeof (struct grub_module_header);
     }
@@ -163,15 +163,17 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
   for (p = path_list; p; p = p->next)
     {
       struct grub_module_header *header;
-      size_t mod_size;
+      size_t mod_size, orig_size;
 
-      mod_size = grub_util_get_image_size (p->name);
+      orig_size = grub_util_get_image_size (p->name);
+      mod_size = ALIGN_UP(orig_size, 4);
 
       header = (struct grub_module_header *) (kernel_img + offset);
       memset (header, 0, sizeof (struct grub_module_header));
       header->type = OBJ_TYPE_ELF;
       header->size = grub_host_to_target32 (mod_size + sizeof (*header));
       offset += sizeof (*header);
+      memset (kernel_img + offset + orig_size, 0, mod_size - orig_size);
 
       grub_util_load_image (p->name, kernel_img + offset);
       offset += mod_size;