From: Michael Tremer Date: Fri, 3 Jan 2025 17:47:40 +0000 (+0000) Subject: ELF: Don't return an error if there are no sections X-Git-Tag: 0.9.30~553 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92edf2e604a52a2d123bdbd6a0790cc5878fc359;p=pakfire.git ELF: Don't return an error if there are no sections Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/elf.c b/src/pakfire/elf.c index 101b1e3f0..f3f2adf03 100644 --- a/src/pakfire/elf.c +++ b/src/pakfire/elf.c @@ -369,8 +369,8 @@ typedef int (*pakfire_elf_foreach_section_callback)(struct pakfire_elf* self, static int pakfire_elf_foreach_section(struct pakfire_elf* self, const Elf64_Word type, pakfire_elf_foreach_section_callback callback, void* data) { Elf_Scn* section = NULL; - GElf_Shdr shdr; - int r = -EINVAL; + GElf_Shdr shdr = {}; + int r; // Walk through all sections for (;;) { @@ -379,7 +379,11 @@ static int pakfire_elf_foreach_section(struct pakfire_elf* self, break; // Fetch the section header - gelf_getshdr(section, &shdr); + if (!gelf_getshdr(section, &shdr)) { + ERROR(self->ctx, "%s: Could not fetch the ELF section header: %s\n", + self->path, elf_errmsg(-1)); + return -EINVAL; + } // Skip sections that don't match if (type && shdr.sh_type != type) @@ -388,10 +392,10 @@ static int pakfire_elf_foreach_section(struct pakfire_elf* self, // Call the callback r = callback(self, section, &shdr, data); if (r) - break; + return r; } - return r; + return 0; } typedef int (*pakfire_elf_dyn_walk_callback)