Restrict sh_link/sh_info evaluation where possible
authornorly <ny-git@enpas.org>
Mon, 27 May 2013 13:53:33 +0000 (14:53 +0100)
committernorly <ny-git@enpas.org>
Mon, 27 May 2013 13:53:33 +0000 (14:53 +0100)
include/libelfu/modeltypes.h
src/model/fromFile.c

index c02eb3405eee72aee6948fbd73f41bdf0818b60d..961f904def535f51ff152e46642bafad01004d4f 100644 (file)
@@ -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;
index 125ea7784fb53bd3e8766eb837bf01068b019a99..bd085f6c61558b75d564f5341c0ddbd02d71804c 100644 (file)
@@ -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];
+          }
       }
     }