1 /* This file is part of centaur.
3 * centaur is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License 2 as
5 * published by the Free Software Foundation.
7 * centaur is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with centaur. If not, see <http://www.gnu.org/licenses/>.
18 #include <sys/types.h>
19 #include <libelfu/libelfu.h>
22 int elfu_mCheck(ElfuElf *me)
28 sortedSecs = elfu_mScnSortedByOffset(me, &numSecs);
34 /* Check for overlapping sections */
35 for (i = 0; i < numSecs - 1; i++) {
36 if (sortedSecs[i]->shdr.sh_offset + SCNFILESIZE(&sortedSecs[i]->shdr)
37 > sortedSecs[i+1]->shdr.sh_offset) {
38 ELFU_WARN("elfu_check: Found overlapping sections: %s and %s.\n",
39 elfu_mScnName(me, sortedSecs[i]),
40 elfu_mScnName(me, sortedSecs[i+1]));
45 /* Check for sections overlapping with EHDR */
46 for (i = 0; i < numSecs; i++) {
47 if (sortedSecs[i]->shdr.sh_offset < me->ehdr.e_ehsize) {
48 ELFU_WARN("elfu_check: Found section overlapping with EHDR: %s.\n",
49 elfu_mScnName(me, sortedSecs[i]));
54 /* Check for sections overlapping with PHDRs */
55 for (i = 0; i < numSecs; i++) {
56 if (OVERLAPPING(sortedSecs[i]->shdr.sh_offset,
57 SCNFILESIZE(&sortedSecs[i]->shdr),
59 me->ehdr.e_phentsize * me->ehdr.e_phnum)) {
60 ELFU_WARN("elfu_check: Found section overlapping with PHDRs: %s.\n",
61 elfu_mScnName(me, sortedSecs[i]));