From: norly Date: Mon, 27 May 2013 13:53:33 +0000 (+0100) Subject: Restrict sh_link/sh_info evaluation where possible X-Git-Url: https://git.enpas.org/?p=centaur.git;a=commitdiff_plain;h=c6fc85f5f72c738c7d1764d1894a33778be6ef31 Restrict sh_link/sh_info evaluation where possible --- diff --git a/include/libelfu/modeltypes.h b/include/libelfu/modeltypes.h index c02eb34..961f904 100644 --- a/include/libelfu/modeltypes.h +++ b/include/libelfu/modeltypes.h @@ -12,7 +12,8 @@ typedef struct ElfuScn { Elf_Data data; - struct ElfuScn *link; + struct ElfuScn *linkptr; + struct ElfuScn *infoptr; CIRCLEQ_ENTRY(ElfuScn) elemPhdrToScn; CIRCLEQ_ENTRY(ElfuScn) elem; diff --git a/src/model/fromFile.c b/src/model/fromFile.c index 125ea77..bd085f6 100644 --- a/src/model/fromFile.c +++ b/src/model/fromFile.c @@ -124,7 +124,8 @@ static ElfuScn* modelFromSection(Elf_Scn *scn) } } - ms->link = NULL; + ms->linkptr = NULL; + ms->infoptr = NULL; return ms; @@ -224,8 +225,22 @@ ElfuElf* elfu_mFromElf(Elf *e) for (i = 0; i < numShdr - 1; i++) { ElfuScn *ms = secArray[i]; - if (ms->shdr.sh_link > 0) { - ms->link = secArray[ms->shdr.sh_link - 1]; + switch (ms->shdr.sh_type) { + case SHT_REL: + case SHT_RELA: + if (ms->shdr.sh_info > 0) { + ms->infoptr = secArray[ms->shdr.sh_info - 1]; + } + case SHT_DYNAMIC: + case SHT_HASH: + case SHT_SYMTAB: + case SHT_DYNSYM: + case SHT_GNU_versym: + case SHT_GNU_verdef: + case SHT_GNU_verneed: + if (ms->shdr.sh_link > 0) { + ms->linkptr = secArray[ms->shdr.sh_link - 1]; + } } }