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 (;;) {
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)
// 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)