Skip to content

Commit 1bb93d4

Browse files
committed
Detect bad e_shstrtab better.
#332 modified: p_lx_elf.cpp
1 parent eb90eab commit 1bb93d4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: src/p_lx_elf.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -2039,11 +2039,12 @@ bool PackLinuxElf32::canPack()
20392039
if (sec_strndx) {
20402040
unsigned const sh_name = get_te32(&sec_strndx->sh_name);
20412041
if (Elf32_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
2042-
|| (u32_t)file_size <= sh_name // FIXME: weak
2042+
|| (u32_t)file_size <= (sizeof(".shstrtab")
2043+
+ sh_name + (shstrtab - (const char *)&file_image[0]))
20432044
|| (sh_name
20442045
&& 0!=strcmp((char const *)".shstrtab", &shstrtab[sh_name]))
20452046
) {
2046-
throwCantPack("bad e_shstrndx");
2047+
throwCantPack("bad e_shstrtab");
20472048
}
20482049
}
20492050
}
@@ -2388,11 +2389,12 @@ PackLinuxElf64::canPack()
23882389
if (sec_strndx) {
23892390
unsigned const sh_name = get_te32(&sec_strndx->sh_name);
23902391
if (Elf64_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
2391-
|| (u32_t)file_size <= sh_name // FIXME: weak
2392+
|| (u32_t)file_size <= (sizeof(".shstrtab")
2393+
+ sh_name + (shstrtab - (const char *)&file_image[0]))
23922394
|| (sh_name
23932395
&& 0!=strcmp((char const *)".shstrtab", &shstrtab[sh_name]))
23942396
) {
2395-
throwCantPack("bad e_shstrndx");
2397+
throwCantPack("bad e_shstrtab");
23962398
}
23972399
}
23982400
}

0 commit comments

Comments
 (0)