Skip to content

Commit

Permalink
Check for possible overflow when checking for segment overlaps. Fix i…
Browse files Browse the repository at this point in the history
…ncorrect range exception message
  • Loading branch information
HoundThe authored and PeterMatula committed Jul 19, 2022
1 parent b87697c commit 457a308
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/retdec/common/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InvalidRangeException : public std::exception

virtual const char* what() const noexcept override
{
return "Invalid Range: end is greater than start";
return "Invalid Range: start is greater than end";
}
};

Expand Down
7 changes: 6 additions & 1 deletion src/loader/loader/pe/pe_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ Segment* PeImage::addSingleSegment(std::uint64_t address, std::vector<std::uint8

bool PeImage::canAddSegment(std::uint64_t address, std::uint64_t memSize) const
{
retdec::common::Range<std::uint64_t> newSegRange(address, memSize ? address + memSize : address + 1);
std::uint64_t end = memSize ? address + memSize : address + 1;
// check for potential overflow - wrap around, memsize should be at most 32bit, so this could suffice
if (end < address)
end = std::numeric_limits<std::uint64_t>::max();

retdec::common::Range<std::uint64_t> newSegRange(address, end);
for (const auto& seg : getSegments())
{
auto overlapResult = OverlapResolver::resolve(retdec::common::Range<std::uint64_t>(seg->getAddress(), seg->getEndAddress()), newSegRange);
Expand Down

0 comments on commit 457a308

Please sign in to comment.