[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] elf: accept elf files without section header table
From: |
Mathieu Mirmont |
Subject: |
[PATCH] elf: accept elf files without section header table |
Date: |
Fri, 03 May 2024 14:35:46 +0000 |
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.
"
Signed-off-by: Mathieu Mirmont <mat@neutrality.ch>
---
grub-core/kern/elfXX.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c
index aabf4b9d7..fe4ffb261 100644
--- a/grub-core/kern/elfXX.c
+++ b/grub-core/kern/elfXX.c
@@ -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)
--
2.30.2
signature.asc
Description: OpenPGP digital signature
- [PATCH] elf: accept elf files without section header table,
Mathieu Mirmont <=