Reject ELF files with section entries smaller than symbol size

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
This commit is contained in:
Alan Jowett 2022-06-09 18:02:30 -06:00 committed by Serge Lamikhov-Center
parent 3e6809cf13
commit fc3c397dd0

View File

@ -42,7 +42,19 @@ template <class S> class symbol_section_accessor_template
Elf_Xword get_symbols_num() const
{
Elf_Xword nRet = 0;
if ( 0 != symbol_section->get_entry_size() &&
size_t minimum_symbol_size;
switch ( elf_file.get_class() ) {
case ELFCLASS32:
minimum_symbol_size = sizeof(Elf32_Sym);
break;
case ELFCLASS64:
minimum_symbol_size = sizeof(Elf64_Sym);
break;
default:
return 0;
}
if ( symbol_section->get_entry_size() >= minimum_symbol_size &&
symbol_section->get_size() <= symbol_section->get_stream_size() ) {
nRet =
symbol_section->get_size() / symbol_section->get_entry_size();