From cdafaa0abfcb7bb689a8d13843d403940a7f5d10 Mon Sep 17 00:00:00 2001
From: Serge Lamikhov-Center <to_serge@users.sourceforge.net>
Date: Fri, 19 Apr 2019 15:05:50 +0300
Subject: [PATCH] Prevent potential dereferencing of NULL pointer

---
 elfio/elfio_section.hpp | 4 ++--
 elfio/elfio_segment.hpp | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

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<char*>( &ph ), sizeof( ph ), '\0' );
-        data = 0;
     }
 
 //------------------------------------------------------------------------------
-- 
GitLab