return r;
}
+static Elf_Scn* pakfire_file_get_elf_section(struct pakfire_file* file,
+ Elf* elf, const Elf64_Word type) {
+ Elf_Scn* section = NULL;
+ GElf_Shdr shdr;
+
+ // Walk through all sections
+ for (;;) {
+ section = elf_nextscn(elf, section);
+ if (!section)
+ break;
+
+ // Fetch the section header
+ gelf_getshdr(section, &shdr);
+
+ // Return any matching sections
+ if (shdr.sh_type == type)
+ return section;
+ }
+
+ // No section found
+ return NULL;
+}
+
static int __pakfire_file_get_elf_type(struct pakfire_file* file, Elf* elf, void* data) {
int* type = (int*)data;
GElf_Ehdr ehdr;
}
static int __pakfire_file_check_debuginfo(struct pakfire_file* file, Elf* elf, void* data) {
- Elf_Scn* section = NULL;
- GElf_Shdr shdr;
-
- // Walk through all sections
- for (;;) {
- section = elf_nextscn(elf, section);
- if (!section)
- break;
-
- // Fetch the section header
- gelf_getshdr(section, &shdr);
-
- switch (shdr.sh_type) {
- // Break if we found the symbol table
- case SHT_SYMTAB:
- return 0;
- }
- }
+ // Fetch the symbol table
+ Elf_Scn* symtab = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB);
// Not found
- DEBUG(file->pakfire, "%s has no debug sections\n", file->path);
+ if (!symtab) {
+ DEBUG(file->pakfire, "%s has no debug sections\n", file->path);
- // Store the result
- file->issues |= PAKFIRE_FILE_MISSING_DEBUGINFO;
+ // Store the result
+ file->issues |= PAKFIRE_FILE_MISSING_DEBUGINFO;
+ }
return 0;
}
static int __pakfire_file_check_ssp(
struct pakfire_file* file, Elf* elf, void* data) {
- Elf_Scn* section = NULL;
- GElf_Shdr section_header;
+ Elf_Scn* symtab = NULL;
+ GElf_Shdr shdr;
Elf_Data* elf_data = NULL;
GElf_Sym symbol;
const char* name = NULL;
- // Count any global functions
- size_t counter = 0;
-
- // Walk through all sections
- for (;;) {
- section = elf_nextscn(elf, section);
- if (!section) {
- ERROR(file->pakfire, "%s has no symbol table\n", file->path);
- return 1;
- }
+ // Fetch the symbol table
+ symtab = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB);
+ if (!symtab) {
+ ERROR(file->pakfire, "%s has no symbol table\n", file->path);
+ return 1;
+ }
- // Fetch the section header
- gelf_getshdr(section, §ion_header);
+ // Fetch the section header
+ gelf_getshdr(symtab, &shdr);
- // Break if we found the symbol table
- if (section_header.sh_type == SHT_SYMTAB)
- break;
- }
+ // Count any global functions
+ size_t counter = 0;
// Fetch a pointer to the section data
- elf_data = elf_getdata(section, NULL);
+ elf_data = elf_getdata(symtab, NULL);
// Walk through all symbols
- for (unsigned int i = 0; i < section_header.sh_size / section_header.sh_entsize; i++) {
+ for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++) {
gelf_getsym(elf_data, i, &symbol);
// Fetch the symbol name
- name = elf_strptr(elf, section_header.sh_link, symbol.st_name);
+ name = elf_strptr(elf, shdr.sh_link, symbol.st_name);
// Skip empty section names
if (!name || !*name)