diff --git a/elfio/elfio_section.hpp b/elfio/elfio_section.hpp index 287392ec257e2f4fc73ac79ada7a1b772b8d4876..3bfc2333c9dc378bdea782b6e08b46a94e8cc65e 100644 --- a/elfio/elfio_section.hpp +++ b/elfio/elfio_section.hpp @@ -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; } } diff --git a/elfio/elfio_segment.hpp b/elfio/elfio_segment.hpp index 09477a30e1fd31a28ccb45fb454a05cdd2b898e8..4074433d07d63130ea61065e818ad99421257e3d 100644 --- a/elfio/elfio_segment.hpp +++ b/elfio/elfio_segment.hpp @@ -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; } //------------------------------------------------------------------------------