Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions elfio/elfio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ class elfio

for ( Elf_Half i = 0; i < num; ++i ) {
section* sec = create_section();

// Load return value is ignored here
// This allows retrieval of information from corrupted sections
sec->load( stream,
static_cast<std::streamoff>( offset ) +
static_cast<std::streampos>( i ) * entry_size,
Expand Down
16 changes: 13 additions & 3 deletions elfio/elfio_section.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,16 @@ template <class T> class section_impl : public section
*/
const char* get_data() const override
{
if ( !is_loaded ) {
load_data();
// If data load failed, the stream is corrupt
// When lazy loading, attempts to call get_data() on it after initial load are useless
// When loading non-lazily, that load_data() will attempt to read data from
// the stream specified on load() call, which might be freed by this point
if ( !is_loaded && can_be_loaded ) {
bool res = load_data();

if ( !res ) {
can_be_loaded = false;
}
}
return data.get();
}
Expand Down Expand Up @@ -434,7 +442,7 @@ template <class T> class section_impl : public section
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );

if ( !( is_lazy || is_loaded ) ) {
bool ret = load_data();
bool ret = get_data();

if ( is_compressed() ) {
Elf_Xword size = get_size();
Expand Down Expand Up @@ -588,6 +596,8 @@ template <class T> class section_impl : public section
false; /**< Flag indicating if lazy loading is enabled. */
mutable bool is_loaded =
false; /**< Flag indicating if the data is loaded. */
mutable bool can_be_loaded =
true; /**< Flag indicating if the data can loaded. This is not the case if the section is corrupted. */
};

} // namespace ELFIO
Expand Down