Pay more attention to 0==.e_shnum
modified: p_lx_elf.cpp
This commit is contained in:
+19
-5
@@ -1826,17 +1826,24 @@ bool PackLinuxElf32::canPack()
|
|||||||
phdri= (Elf32_Phdr *)((size_t)e_phoff + file_image); // do not free() !!
|
phdri= (Elf32_Phdr *)((size_t)e_phoff + file_image); // do not free() !!
|
||||||
shdri= (Elf32_Shdr *)((size_t)e_shoff + file_image); // do not free() !!
|
shdri= (Elf32_Shdr *)((size_t)e_shoff + file_image); // do not free() !!
|
||||||
|
|
||||||
|
if (!e_shnum) {
|
||||||
|
sec_strndx = NULL;
|
||||||
|
shstrtab = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
sec_strndx = &shdri[get_te16(&ehdr->e_shstrndx)];
|
sec_strndx = &shdri[get_te16(&ehdr->e_shstrndx)];
|
||||||
shstrtab = (char const *)(get_te32(&sec_strndx->sh_offset) + file_image);
|
shstrtab = (char const *)(get_te32(&sec_strndx->sh_offset) + file_image);
|
||||||
sec_dynsym = elf_find_section_type(Elf32_Shdr::SHT_DYNSYM);
|
sec_dynsym = elf_find_section_type(Elf32_Shdr::SHT_DYNSYM);
|
||||||
if (sec_dynsym)
|
if (sec_dynsym) {
|
||||||
sec_dynstr = get_te32(&sec_dynsym->sh_link) + shdri;
|
sec_dynstr = get_te32(&sec_dynsym->sh_link) + shdri;
|
||||||
|
}
|
||||||
|
|
||||||
if (Elf32_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
|
if (Elf32_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
|
||||||
|| 0!=strcmp((char const *)".shstrtab",
|
|| 0!=strcmp((char const *)".shstrtab",
|
||||||
&shstrtab[get_te32(&sec_strndx->sh_name)]) ) {
|
&shstrtab[get_te32(&sec_strndx->sh_name)]) ) {
|
||||||
throwCantPack("bad e_shstrndx");
|
throwCantPack("bad e_shstrndx");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
phdr= phdri;
|
phdr= phdri;
|
||||||
for (int j= e_phnum; --j>=0; ++phdr)
|
for (int j= e_phnum; --j>=0; ++phdr)
|
||||||
@@ -2078,17 +2085,24 @@ PackLinuxElf64::canPack()
|
|||||||
phdri= (Elf64_Phdr *)((size_t)e_phoff + file_image); // do not free() !!
|
phdri= (Elf64_Phdr *)((size_t)e_phoff + file_image); // do not free() !!
|
||||||
shdri= (Elf64_Shdr *)((size_t)e_shoff + file_image); // do not free() !!
|
shdri= (Elf64_Shdr *)((size_t)e_shoff + file_image); // do not free() !!
|
||||||
|
|
||||||
sec_dynsym = elf_find_section_type(Elf64_Shdr::SHT_DYNSYM);
|
if (!e_shnum) {
|
||||||
if (sec_dynsym)
|
sec_strndx = NULL;
|
||||||
sec_dynstr = get_te32(&sec_dynsym->sh_link) + shdri;
|
shstrtab = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
sec_strndx = &shdri[get_te16(&ehdr->e_shstrndx)];
|
sec_strndx = &shdri[get_te16(&ehdr->e_shstrndx)];
|
||||||
shstrtab = (char const *)(get_te64(&sec_strndx->sh_offset) + file_image);
|
shstrtab = (char const *)(get_te64(&sec_strndx->sh_offset) + file_image);
|
||||||
|
sec_dynsym = elf_find_section_type(Elf64_Shdr::SHT_DYNSYM);
|
||||||
|
if (sec_dynsym) {
|
||||||
|
sec_dynstr = get_te32(&sec_dynsym->sh_link) + shdri;
|
||||||
|
}
|
||||||
|
|
||||||
if (Elf64_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
|
if (Elf64_Shdr::SHT_STRTAB != get_te32(&sec_strndx->sh_type)
|
||||||
|| 0!=strcmp((char const *)".shstrtab",
|
|| 0!=strcmp((char const *)".shstrtab",
|
||||||
&shstrtab[get_te32(&sec_strndx->sh_name)]) ) {
|
&shstrtab[get_te32(&sec_strndx->sh_name)]) ) {
|
||||||
throwCantPack("bad e_shstrndx");
|
throwCantPack("bad e_shstrndx");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
phdr= phdri;
|
phdr= phdri;
|
||||||
for (int j= e_phnum; --j>=0; ++phdr)
|
for (int j= e_phnum; --j>=0; ++phdr)
|
||||||
|
|||||||
Reference in New Issue
Block a user