Simplify includes
[centaur.git] / src / elfops / check.c
index 8aaa7b55291df3fefc2448b6761f77c4a710163e..2c7f040910dee5e28421e0a389867687ed867a86 100644 (file)
@@ -1,7 +1,5 @@
 #include <assert.h>
 #include <stdlib.h>
-#include <libelf/libelf.h>
-#include <libelf/gelf.h>
 #include <libelfu/libelfu.h>
 
 int elfu_eCheck(Elf *e)
@@ -160,6 +158,25 @@ int elfu_eCheck(Elf *e)
           goto ERROR;
         }
       }
+
+      /* Section addr/offset should match parent PHDR.
+       * Find parent PHDR: */
+      for (j = 0; j < numPhdr; j++) {
+        if (PHDR_CONTAINS_SCN_IN_MEMORY(&phdrs[j], &shdrs[i])) {
+          GElf_Off shoff = phdrs[j].p_offset + (shdrs[i].sh_addr - phdrs[j].p_vaddr);
+
+          if (shdrs[i].sh_offset != shoff
+              || !PHDR_CONTAINS_SCN_IN_FILE(&phdrs[j], &shdrs[i])) {
+            ELFU_WARN("elfu_eCheck: Memory/file offsets/sizes are not congruent for SHDR %d, PHDR %d.\n", i, j);
+            goto ERROR;
+          }
+        }
+      }
+
+      /* sh_link members should not point to sections out of range. */
+      if (shdrs[i].sh_link >= numShdr) {
+        ELFU_WARN("elfu_eCheck: Bogus sh_link in SHDR %d.\n", i);
+      }
     }
   }