// ELF Header
GElf_Ehdr ehdr;
+ // Number of Program Headers
+ size_t phnum;
+
// Strings
size_t shstrndx;
return -EINVAL;
}
+ // Fetch the total numbers of program headers
+ r = elf_getphdrnum(self->elf, &self->phnum);
+ if (r) {
+ ERROR(self->ctx,
+ "Could not fetch number of program headers: %s\n", elf_errmsg(-1));
+ return -EINVAL;
+ }
+
// Find the strings
r = elf_getshdrstrndx(self->elf, &self->shstrndx);
if (r < 0) {
int pakfire_elf_has_execstack(struct pakfire_elf* self) {
GElf_Phdr phdr;
- int r;
-
- size_t phnum = 0;
-
- // Fetch the total numbers of program headers
- r = elf_getphdrnum(self->elf, &phnum);
- if (r) {
- ERROR(self->ctx,
- "Could not fetch number of program headers: %s\n", elf_errmsg(-1));
- return -EINVAL;
- }
// Walk through all program headers
- for (unsigned int i = 0; i < phnum; i++) {
+ for (unsigned int i = 0; i < self->phnum; i++) {
if (!gelf_getphdr(self->elf, i, &phdr)) {
ERROR(self->ctx, "Could not parse program header: %s\n", elf_errmsg(-1));
return -ENOTSUP;