Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for ELF damage #1036

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions include/retdec/fileformat/file_format/elf/elf_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
namespace retdec {
namespace fileformat {

enum ElfLoaderError : std::uint32_t
{
LDR_ERROR_NONE = 0,
LDR_ERROR_SEGMENT_OUT_OF_FILE
};

/**
* ElfFormat - wrapper for parsing ELF files
*/
Expand Down
12 changes: 12 additions & 0 deletions src/fileformat/file_format/elf/elf_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,18 @@ void ElfFormat::loadSegments()
fSeg->setElfAlign(seg->get_align());
fSeg->load(this);
segments.push_back(fSeg);

HoundThe marked this conversation as resolved.
Show resolved Hide resolved
auto filesize = fSeg->getSizeInFile();
auto fileoffset = fSeg->getOffset();
int segtype = seg->get_type();

// Check if LOAD segments are actually in the file
if (segtype == PT_LOAD && getFileLength() < fileoffset + filesize)
{
_ldrErrInfo.loaderErrorCode = ElfLoaderError::LDR_ERROR_SEGMENT_OUT_OF_FILE;
_ldrErrInfo.loaderError = "Segment data is not within file bounds";
_ldrErrInfo.loaderErrorUserFriendly = "Segment data is not within file bounds";
HoundThe marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down