elf: accept elf files without section header table
PATCH 1/1 elf: accept elf files without section header table
It isn't an error for an elf executable to be lacking a section header table. In this case we should just be returning shnum = 0.
According to the elf(5) manual page:
"e_shoff This member holds the section header table's file offset in
bytes. If the file has no section header table, this member holds zero.
"
--- grub-core/kern/elfXX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
grub-core/kern/elfXX.c +0 -0
@@ -220,12 +220,12 @@ grub_elfXX_get_shnum (ElfXX_Ehdr *e, ElfXX_Shnum *shnum)if (e ==NULL ) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("NULL pointer passed
for elf header"));
+ if (e->e_shoff == 0)
+ return GRUB_ERR_NONE;
+
*shnum = e->e_shnum;
if (*shnum == SHN_UNDEF)
{- if (e->e_shoff == 0)
-
return grub_error (GRUB_ERR_BAD_NUMBER, N_("invalid section header table offset in e_shoff")); -
s = (ElfXX_Shdr *) ((grub_uint8_t *) e + e->e_shoff);
*shnum = s->sh_size;
if (*shnum < SHN_LORESERVE)Signature · 1 line
2.30.2
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Hey. Can you describe what exactly are you trying to solve?
Quoted 39 lines · Mathieu Mirmont
It isn't an error for an elf executable to be lacking a section header table. In this case we should just be returning shnum = 0.
According to the elf(5) manual page:
"e_shoffThis member holds the section header table's file offset in
bytes. If the file has no section header table, this member holds zero.
"Signed-off-by Mathieu Mirmont <[email protected]>--- grub-core/kern/elfXX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)grub-core/kern/elfXX.c +3
-2@@ -220,12 +220,12 @@ grub_elfXX_get_shnum (ElfXX_Ehdr *e, ElfXX_Shnum *shnum) if (e == NULL) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("NULL pointer passed for elf header")); + if (e->e_shoff == 0) + return GRUB_ERR_NONE; + *shnum = e->e_shnum; if (*shnum == SHN_UNDEF) { - if (e->e_shoff == 0) -return
grub_error(GRUB_ERR_BAD_NUMBER,N_("invalid section header table offset in e_shoff"));
-s = (ElfXX_Shdr *) ((grub_uint8_t *) e + e->e_shoff); *shnum = s->sh_size; if (*shnum < SHN_LORESERVE)
Quoted 7 lines
--
2.30.2
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel