Prevent potential dereferencing of NULL pointer

This commit is contained in:
Serge Lamikhov-Center 2019-04-19 15:05:50 +03:00
parent 858b7a3b70
commit cdafaa0abf
2 changed files with 3 additions and 4 deletions

View File

@ -251,10 +251,10 @@ class section_impl : public section
data_size = 0;
}
if ( 0 != size ) {
if ( ( 0 != size ) && ( 0 != data ) ) {
stream.seekg( (*convertor)( header.sh_offset ) );
stream.read( data, size );
data[size] = 0; //ensure data is ended with 0 to avoid oob read
data[size] = 0; // Ensure data is ended with 0 to avoid oob read
data_size = size;
}
}

View File

@ -69,11 +69,10 @@ class segment_impl : public segment
public:
//------------------------------------------------------------------------------
segment_impl( endianess_convertor* convertor_ ) :
convertor( convertor_ )
convertor( convertor_ ), stream_size( 0 ), index( 0 ), data( 0 )
{
is_offset_set = false;
std::fill_n( reinterpret_cast<char*>( &ph ), sizeof( ph ), '\0' );
data = 0;
}
//------------------------------------------------------------------------------