diff --git a/elfio/elfio_section.hpp b/elfio/elfio_section.hpp index 287392e..3bfc233 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 09477a3..4074433 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( &ph ), sizeof( ph ), '\0' ); - data = 0; } //------------------------------------------------------------------------------