]> git.ipfire.org Git - pakfire.git/commitdiff
ELF: Don't return an error if there are no sections
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 17:47:40 +0000 (17:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 17:47:40 +0000 (17:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/elf.c

index 101b1e3f06f693372a875e4a78cc4c9eb075ffe8..f3f2adf03d2b167f7cb1989d16c892f6becc4cef 100644 (file)
@@ -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)