Data size boundary check for dynamic section reader

Permit section data allocation for size equal to 0
This commit is contained in:
Serge Lamikhov-Center 2013-01-30 14:45:35 +02:00
parent cde39c9d45
commit 79ecb3fabc
2 changed files with 8 additions and 6 deletions

View File

@ -126,7 +126,8 @@ class dynamic_section_accessor
const endianess_convertor& convertor = elf_file.get_convertor();
// Check unusual case when dynamic section has no data
if( dynamic_section->get_data() == 0 ) {
if( dynamic_section->get_data() == 0 ||
( index + 1 ) * dynamic_section->get_entry_size() > dynamic_section->get_size() ) {
tag = DT_NULL;
value = 0;
return;

View File

@ -211,12 +211,13 @@ class section_impl : public section
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );
Elf_Xword size = get_size();
if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() &&
0 != size ) {
if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() ) {
data = new char[size];
stream.seekg( (*convertor)( header.sh_offset ) );
stream.read( data, size );
data_size = size;
if ( 0 != size ) {
stream.seekg( (*convertor)( header.sh_offset ) );
stream.read( data, size );
data_size = size;
}
}
}