Make sure that dynamic section entry size is larger than ElfXX_Dyn structure

This commit is contained in:
Serge Lamikhov-Center 2022-06-19 23:21:56 +03:00
parent cf954a8d42
commit ee891ca7c9
2 changed files with 13 additions and 3 deletions

2
.vscode/launch.json vendored
View File

@ -102,7 +102,7 @@
"request": "launch",
"program": "${workspaceFolder}/tests/elfio_fuzzer",
"args": [
"crash-98819328ee414bbba1ee50073d66c0727d60a7af"
"oom-9025696a52c7f5cb94d482225a6b3727e9691f5b"
],
"cwd": "${workspaceFolder}/tests",
}

View File

@ -40,8 +40,17 @@ template <class S> class dynamic_section_accessor_template
//------------------------------------------------------------------------------
Elf_Xword get_entries_num() const
{
size_t needed_entry_size = -1;
if ( elf_file.get_class() == ELFCLASS32 ) {
needed_entry_size = sizeof( Elf32_Dyn );
}
else {
needed_entry_size = sizeof( Elf64_Dyn );
}
if ( ( 0 == entries_num ) &&
( 0 != dynamic_section->get_entry_size() ) ) {
( 0 != dynamic_section->get_entry_size() &&
dynamic_section->get_entry_size() >= needed_entry_size ) ) {
entries_num =
dynamic_section->get_size() / dynamic_section->get_entry_size();
Elf_Xword i;
@ -134,7 +143,8 @@ template <class S> class dynamic_section_accessor_template
// Check unusual case when dynamic section has no data
if ( dynamic_section->get_data() == nullptr ||
( index + 1 ) * dynamic_section->get_entry_size() >
dynamic_section->get_size() ) {
dynamic_section->get_size() ||
dynamic_section->get_entry_size() < sizeof( T ) ) {
tag = DT_NULL;
value = 0;
return;