forked from len0rd/rockbox
sbtools: fortify code against weird elf files with no string table and/or no sections/programs headers !
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29747 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c2ca4bec9d
commit
79c6aca566
1 changed files with 11 additions and 6 deletions
|
@ -199,7 +199,6 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *use
|
|||
uint32_t shstrtab_strtbl = text_strtbl + strlen(".text") + 1;
|
||||
uint32_t strtbl_size = shstrtab_strtbl + strlen(".shstrtab") + 1;
|
||||
|
||||
|
||||
while(sec)
|
||||
{
|
||||
if(sec->type == EST_LOAD)
|
||||
|
@ -368,14 +367,15 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
|
|||
error_printf("invalid elf file: must target an arm machine\n");
|
||||
if(ehdr.e_ehsize != sizeof(ehdr))
|
||||
error_printf("invalid elf file: size header mismatch\n");
|
||||
if(ehdr.e_phentsize != sizeof(Elf32_Phdr))
|
||||
if(ehdr.e_phnum > 0 && ehdr.e_phentsize != sizeof(Elf32_Phdr))
|
||||
error_printf("invalid elf file: program header size mismatch\n");
|
||||
if(ehdr.e_shentsize != sizeof(Elf32_Shdr))
|
||||
if(ehdr.e_shnum > 0 && ehdr.e_shentsize != sizeof(Elf32_Shdr))
|
||||
error_printf("invalid elf file: section header size mismatch\n");
|
||||
if(ehdr.e_flags & EF_ARM_HASENTRY)
|
||||
elf_set_start_addr(params, ehdr.e_entry);
|
||||
|
||||
char *strtab = NULL;
|
||||
if(ehdr.e_shstrndx != SHN_UNDEF)
|
||||
{
|
||||
Elf32_Shdr shstrtab;
|
||||
if(read(user, ehdr.e_shoff + ehdr.e_shstrndx * ehdr.e_shentsize,
|
||||
|
@ -406,15 +406,20 @@ bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
|
|||
error_printf("error read self section data");
|
||||
elf_add_load_section(params, shdr.sh_addr, shdr.sh_size, data);
|
||||
|
||||
if(strtab)
|
||||
printf(user, false, "create load segment for %s\n", &strtab[shdr.sh_name]);
|
||||
}
|
||||
else if(shdr.sh_type == SHT_NOBITS && shdr.sh_flags & SHF_ALLOC)
|
||||
{
|
||||
elf_add_fill_section(params, shdr.sh_addr, shdr.sh_size, 0);
|
||||
if(strtab)
|
||||
printf(user, false, "create fill segment for %s\n", &strtab[shdr.sh_name]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strtab)
|
||||
printf(user, false, "filter out %s\n", &strtab[shdr.sh_name], shdr.sh_type);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue