commit 4adcea0d7a4114015d85ec8761fefb6a84a226cb
parent 079a75d572618f49ce9ce3249122e0596e7b4782
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 22 Jan 2025 10:19:40 +0100
libmach/elf: Ensure section information is always correct
The code was not handling correctly the cases where no section information
was placed in the binary and it could have pointers and variables without
a correct value.
Diffstat:
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/libmach/elf64/elf64read.c b/src/libmach/elf64/elf64read.c
@@ -166,6 +166,8 @@ readshdr(Obj *obj, FILE *fp)
elf = obj->data;
hdr = &elf->hdr;
+ elf->nsec = 0;
+ elf->shdr = NULL;
if (hdr->e_shoff == 0)
return 1;
@@ -192,6 +194,8 @@ readshdr(Obj *obj, FILE *fp)
if (nsec > SIZE_MAX)
return 0;
+ if (nsec == 0)
+ return 1;
shdr = calloc(nsec, sizeof(*shdr));
if (!shdr)