grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/6] util/grub-module-verifierXX.c: Changed get_shnum() return ty


From: Alec Brown
Subject: [PATCH 6/6] util/grub-module-verifierXX.c: Changed get_shnum() return type
Date: Thu, 26 May 2022 15:29:52 -0400

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>
---
 util/grub-module-verifierXX.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
index cf3ff0dfa..8e0cd91d9 100644
--- a/util/grub-module-verifierXX.c
+++ b/util/grub-module-verifierXX.c
@@ -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;
-- 
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]