Abstract model more - break 'make check'
[centaur.git] / src / elfops / check.c
index 8aaa7b55291df3fefc2448b6761f77c4a710163e..daf6542698fb8171dc681ff570b484ac4c10f713 100644 (file)
@@ -160,6 +160,22 @@ 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])) {
+          if (!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);
+      }
     }
   }