Commit bc5f17b0 authored by alvaro's avatar alvaro Committed by Serge Lamikhov-Center
Browse files

Fix more NULL dereferences

Crash 7d695153fd8052529d480c2352d4ada33a44bada
parent abab9944
......@@ -50,19 +50,21 @@ THE SOFTWARE.
TYPE \
get_##FNAME() const \
{ \
return header->get_##FNAME(); \
return header? header->get_##FNAME() : 0; \
}
#define ELFIO_HEADER_ACCESS_GET_SET( TYPE, FNAME ) \
TYPE \
get_##FNAME() const \
{ \
return header->get_##FNAME(); \
return header? header->get_##FNAME() : 0; \
} \
void \
set_##FNAME( TYPE val ) \
{ \
header->set_##FNAME( val ); \
{ \
if (header) { \
header->set_##FNAME( val ); \
} \
} \
namespace ELFIO {
......
......@@ -429,18 +429,22 @@ class dump
//------------------------------------------------------------------------------
static void
header( std::ostream& out, const elfio& reader )
{
out << "ELF Header" << std::endl << std::endl
<< " Class: " << str_class( reader.get_class() ) << std::endl
<< " Encoding: " << str_endian( reader.get_encoding() ) << std::endl
<< " ELFVersion: " << str_version( reader.get_elf_version() ) << std::endl
<< " Type: " << str_type( reader.get_type() ) << std::endl
<< " Machine: " << str_machine( reader.get_machine() ) << std::endl
<< " Version: " << str_version( reader.get_version() ) << std::endl
<< " Entry: " << "0x" << std::hex << reader.get_entry() << std::endl
<< " Flags: " << "0x" << std::hex << reader.get_flags() << std::endl
<< std::endl;
}
{
if (!reader.get_header_size())
{
return;
}
out << "ELF Header" << std::endl << std::endl
<< " Class: " << str_class( reader.get_class() ) << std::endl
<< " Encoding: " << str_endian( reader.get_encoding() ) << std::endl
<< " ELFVersion: " << str_version( reader.get_elf_version() ) << std::endl
<< " Type: " << str_type( reader.get_type() ) << std::endl
<< " Machine: " << str_machine( reader.get_machine() ) << std::endl
<< " Version: " << str_version( reader.get_version() ) << std::endl
<< " Entry: " << "0x" << std::hex << reader.get_entry() << std::endl
<< " Flags: " << "0x" << std::hex << reader.get_flags() << std::endl
<< std::endl;
}
//------------------------------------------------------------------------------
static void
......
......@@ -42,8 +42,8 @@ class elf_header
ELFIO_GET_ACCESS_DECL( Elf_Half, section_entry_size );
ELFIO_GET_ACCESS_DECL( Elf_Half, segment_entry_size );
ELFIO_GET_SET_ACCESS_DECL( Elf_Word, version );
ELFIO_GET_SET_ACCESS_DECL( unsigned char, os_abi );
ELFIO_GET_SET_ACCESS_DECL( Elf_Word, version );
ELFIO_GET_SET_ACCESS_DECL( unsigned char, os_abi );
ELFIO_GET_SET_ACCESS_DECL( unsigned char, abi_version );
ELFIO_GET_SET_ACCESS_DECL( Elf_Half, type );
ELFIO_GET_SET_ACCESS_DECL( Elf_Half, machine );
......@@ -123,8 +123,8 @@ template< class T > class elf_header_impl : public elf_header
ELFIO_GET_ACCESS( Elf_Half, section_entry_size, header.e_shentsize );
ELFIO_GET_ACCESS( Elf_Half, segment_entry_size, header.e_phentsize );
ELFIO_GET_SET_ACCESS( Elf_Word, version, header.e_version);
ELFIO_GET_SET_ACCESS( unsigned char, os_abi, header.e_ident[EI_OSABI] );
ELFIO_GET_SET_ACCESS( Elf_Word, version, header.e_version);
ELFIO_GET_SET_ACCESS( unsigned char, os_abi, header.e_ident[EI_OSABI] );
ELFIO_GET_SET_ACCESS( unsigned char, abi_version, header.e_ident[EI_ABIVERSION] );
ELFIO_GET_SET_ACCESS( Elf_Half, type, header.e_type );
ELFIO_GET_SET_ACCESS( Elf_Half, machine, header.e_machine );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment