From ecc45ede27ee442ef8591d5f86f044acd3672d75 Mon Sep 17 00:00:00 2001 From: Tim Strazzere Date: Thu, 21 Apr 2016 13:32:57 -0700 Subject: [PATCH] Prevent accessing pdata struct if it doesn't exist. --- elfio/elfio_dump.hpp | 56 ++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/elfio/elfio_dump.hpp b/elfio/elfio_dump.hpp index ec81ab4..232b4f1 100644 --- a/elfio/elfio_dump.hpp +++ b/elfio/elfio_dump.hpp @@ -775,23 +775,25 @@ class dump out << sec->get_name() << std::endl; const char* pdata = sec->get_data(); - ELFIO::Elf_Xword i; - for ( i = 0; i < std::min( sec->get_size(), MAX_DATA_ENTRIES ); ++i ) { - if ( i % 16 == 0 ) { - out << "[" << DUMP_HEX_FORMAT( 8 ) << i << "]"; + if ( pdata ){ + ELFIO::Elf_Xword i; + for ( i = 0; i < std::min( sec->get_size(), MAX_DATA_ENTRIES ); ++i ) { + if ( i % 16 == 0 ) { + out << "[" << DUMP_HEX_FORMAT( 8 ) << i << "]"; + } + + out << " " << DUMP_HEX_FORMAT( 2 ) << ( pdata[i] & 0x000000FF ); + + if ( i % 16 == 15 ) { + out << std::endl; + } } - - out << " " << DUMP_HEX_FORMAT( 2 ) << ( pdata[i] & 0x000000FF ); - - if ( i % 16 == 15 ) { + if ( i % 16 != 0 ) { out << std::endl; } - } - if ( i % 16 != 0 ) { - out << std::endl; - } - out.flags(original_flags); + out.flags(original_flags); + } return; } @@ -827,23 +829,25 @@ class dump out << "Segment # " << no << std::endl; const char* pdata = seg->get_data(); - ELFIO::Elf_Xword i; - for ( i = 0; i < std::min( seg->get_file_size(), MAX_DATA_ENTRIES ); ++i ) { - if ( i % 16 == 0 ) { - out << "[" << DUMP_HEX_FORMAT( 8 ) << i << "]"; + if ( pdata ) { + ELFIO::Elf_Xword i; + for ( i = 0; i < std::min( seg->get_file_size(), MAX_DATA_ENTRIES ); ++i ) { + if ( i % 16 == 0 ) { + out << "[" << DUMP_HEX_FORMAT( 8 ) << i << "]"; + } + + out << " " << DUMP_HEX_FORMAT( 2 ) << ( pdata[i] & 0x000000FF ); + + if ( i % 16 == 15 ) { + out << std::endl; + } } - - out << " " << DUMP_HEX_FORMAT( 2 ) << ( pdata[i] & 0x000000FF ); - - if ( i % 16 == 15 ) { + if ( i % 16 != 0 ) { out << std::endl; } - } - if ( i % 16 != 0 ) { - out << std::endl; - } - out.flags(original_flags); + out.flags(original_flags); + } return; }