]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
util/grub-module-verifierXX: Changed get_shnum() return type
authorAlec Brown <alec.r.brown@oracle.com>
Fri, 12 Aug 2022 22:25:48 +0000 (18:25 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Fri, 19 Aug 2022 20:30:44 +0000 (22:30 +0200)
In util/grub-module-verifierXX.c, the function get_shnum() returns the variable
shnum, which is of the type Elf_Word. In the function, shnum can be obtained by
the e_shnum member of an Elf_Ehdr or the sh_size member of an Elf_Shdr. The
sh_size member can either be grub_uint32_t or grub_uint64_t, depending on the
architecture, but Elf_Word is only grub_uint32_t. To account for when sh_size is
grub_uint64_t, we can set shnum to have type Elf_Shnum and have get_shnum()
return an Elf_Shnum.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-module-verifierXX.c

index cf3ff0dfa27a36fe639d4f04319092e1dd2f9a99..8e0cd91d900564b0578e6a078254125493decb4e 100644 (file)
@@ -18,6 +18,7 @@
 # define Elf_Rel        Elf32_Rel
 # define Elf_Word       Elf32_Word
 # define Elf_Half       Elf32_Half
+# define Elf_Shnum      Elf32_Shnum
 # define Elf_Section    Elf32_Section
 # define ELF_R_SYM(val)                ELF32_R_SYM(val)
 # define ELF_R_TYPE(val)               ELF32_R_TYPE(val)
@@ -36,6 +37,7 @@
 # define Elf_Rel        Elf64_Rel
 # define Elf_Word       Elf64_Word
 # define Elf_Half       Elf64_Half
+# define Elf_Shnum      Elf64_Shnum
 # define Elf_Section    Elf64_Section
 # define ELF_R_SYM(val)                ELF64_R_SYM(val)
 # define ELF_R_TYPE(val)               ELF64_R_TYPE(val)
@@ -141,11 +143,11 @@ get_shdr (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word in
                       index * grub_target_to_host16 (e->e_shentsize));
 }
 
-static Elf_Word
+static Elf_Shnum
 get_shnum (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
 {
   Elf_Shdr *s;
-  Elf_Word shnum;
+  Elf_Shnum shnum;
 
   shnum = grub_target_to_host16 (e->e_shnum);
   if (shnum == SHN_UNDEF)
@@ -153,12 +155,12 @@ get_shnum (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
       s = get_shdr (arch, e, 0);
       shnum = grub_target_to_host (s->sh_size);
       if (shnum < SHN_LORESERVE)
-       grub_util_error ("Invalid number of section header table entries in sh_size: %d", shnum);
+       grub_util_error ("Invalid number of section header table entries in sh_size: %" PRIuGRUB_UINT64_T, (grub_uint64_t) shnum);
     }
   else
     {
       if (shnum >= SHN_LORESERVE)
-       grub_util_error ("Invalid number of section header table entries in e_shnum: %d", shnum);
+       grub_util_error ("Invalid number of section header table entries in e_shnum: %" PRIuGRUB_UINT64_T, (grub_uint64_t) shnum);
     }
 
   return shnum;