diff options
author | norly <ny-git@enpas.org> | 2013-05-27 14:53:33 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-05-27 14:53:33 +0100 |
commit | c6fc85f5f72c738c7d1764d1894a33778be6ef31 (patch) | |
tree | 8f0d35c37a9d1b26297e0f40af8948160d83b6ad | |
parent | 147edc30e5afb3fa0b17727fde972a0c1a9b275f (diff) |
Restrict sh_link/sh_info evaluation where possible
-rw-r--r-- | include/libelfu/modeltypes.h | 3 | ||||
-rw-r--r-- | src/model/fromFile.c | 21 |
2 files changed, 20 insertions, 4 deletions
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]; + } } } |