Skip to content
Permalink
Browse files Browse the repository at this point in the history
Detect bad e_shstrtab better.
#332
	modified:   p_lx_elf.cpp
  • Loading branch information
jreiser committed Jan 14, 2020
1 parent eb90eab commit 1bb93d4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/p_lx_elf.cpp
Expand Up @@ -2039,11 +2039,12 @@ bool PackLinuxElf32::canPack()
if (sec_strndx) {
unsigned const sh_name = get_te32(&sec_strndx->sh_name);
if (Elf32_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
|| (u32_t)file_size <= sh_name // FIXME: weak
|| (u32_t)file_size <= (sizeof(".shstrtab")
+ sh_name + (shstrtab - (const char *)&file_image[0]))
|| (sh_name
&& 0!=strcmp((char const *)".shstrtab", &shstrtab[sh_name]))
) {
throwCantPack("bad e_shstrndx");
throwCantPack("bad e_shstrtab");
}
}
}
Expand Down Expand Up @@ -2388,11 +2389,12 @@ PackLinuxElf64::canPack()
if (sec_strndx) {
unsigned const sh_name = get_te32(&sec_strndx->sh_name);
if (Elf64_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
|| (u32_t)file_size <= sh_name // FIXME: weak
|| (u32_t)file_size <= (sizeof(".shstrtab")
+ sh_name + (shstrtab - (const char *)&file_image[0]))
|| (sh_name
&& 0!=strcmp((char const *)".shstrtab", &shstrtab[sh_name]))
) {
throwCantPack("bad e_shstrndx");
throwCantPack("bad e_shstrtab");
}
}
}
Expand Down

0 comments on commit 1bb93d4

Please sign in to comment.