}
typedef int (*pakfire_elf_foreach_section_callback)(struct pakfire_elf* self,
- const Elf_Scn* section, const GElf_Shdr* shdr, Elf_Data* data);
+ Elf_Scn* section, const GElf_Shdr* shdr, void* data);
static int pakfire_elf_foreach_section(struct pakfire_elf* self,
- const Elf64_Word type, pakfire_elf_foreach_section_callback callback) {
+ const Elf64_Word type, pakfire_elf_foreach_section_callback callback, void* data) {
Elf_Scn* section = NULL;
GElf_Shdr shdr;
- Elf_Data* data;
int r = -EINVAL;
// Walk through all sections
if (type && shdr.sh_type != type)
continue;
- // Fetch the data
- data = elf_getdata(section, NULL);
-
// Call the callback
r = callback(self, section, &shdr, data);
if (r)
}
static int pakfire_elf_check_cf_protection(struct pakfire_elf* self,
- const Elf_Scn* section, const GElf_Shdr* shdr, Elf_Data* data) {
+ Elf_Scn* section, const GElf_Shdr* shdr, void* data) {
GElf_Nhdr nhdr = {};
size_t offset = 0;
size_t offset_name = 0;
size_t offset_data = 0;
int r;
+ // Fetch data
+ Elf_Data* d = elf_getdata(section, NULL);
+
// Fetch the .note header
offset = gelf_getnote(data, offset, &nhdr, &offset_name, &offset_data);
if (!offset) {
// Fetch the endianess
const int endianess = pakfire_elf_endianess(self);
- const char* payload = (const char*)data->d_buf + offset_data;
+ const char* payload = (const char*)d->d_buf + offset_data;
while (length) {
// Read the type and size of the .note section
}
int pakfire_elf_has_cf_protection(struct pakfire_elf* self) {
- return pakfire_elf_foreach_section(self, SHT_NOTE, pakfire_elf_check_cf_protection);
+ return pakfire_elf_foreach_section(self, SHT_NOTE, pakfire_elf_check_cf_protection, NULL);
}
static int pakfire_elf_check_runpath(struct pakfire_elf* self,
}
static int __pakfire_elf_is_stripped(struct pakfire_elf* self,
- const Elf_Scn* section, const Elf64_Shdr* shdr, Elf_Data* data) {
+ Elf_Scn* section, const Elf64_Shdr* shdr, void* data) {
// Fetch the section name
const char* name = elf_strptr(self->elf, self->shstrndx, shdr->sh_name);
if (!name)
}
// Run through all sections
- r = pakfire_elf_foreach_section(self, SHT_NULL, __pakfire_elf_is_stripped);
+ r = pakfire_elf_foreach_section(self, SHT_NULL, __pakfire_elf_is_stripped, NULL);
if (r < 0)
return r;