[PATCH] libelf: Reject class zero (no Ehdr) in elf_getdata_rawchunk
Mark Wielaard
mark@klomp.org
Sun Nov 8 00:49:45 GMT 2026
An Elf descriptor has a "zero" class until the Ehdr is created.
elf_getdata_rawchunk needs a valid class for the align table lookup.
* libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk): Return
NULL and set libelf errno to ELF_E_WRONG_ORDER_EHDR, when
class is 0.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libelf/elf_getdata_rawchunk.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libelf/elf_getdata_rawchunk.c b/libelf/elf_getdata_rawchunk.c
index cbda7046f9df..d2610b6efa97 100644
--- a/libelf/elf_getdata_rawchunk.c
+++ b/libelf/elf_getdata_rawchunk.c
@@ -81,6 +81,13 @@ elf_getdata_rawchunk (Elf *elf, int64_t offset, size_t size, Elf_Type type)
return NULL;
}
+ /* Class is set from the Ehdr. */
+ if (unlikely (elf->class == 0))
+ {
+ __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
+ return NULL;
+ }
+
/* Get the raw bytes from the file. */
void *rawchunk;
int flags = 0;
--
2.56.0
More information about the Elfutils-devel
mailing list