Skip to content

Commit

Permalink
[lld-macho][nfc]Add bounds on sections and subsections check before a…
Browse files Browse the repository at this point in the history
…ttempting to dereferencing iterators.

Runnign some tests with asan built of LLD would throw errors similar to the following:

AddressSanitizer:DEADLYSIGNAL
    #0 0x55d8e6da5df7 in operator() /mnt/ssd/repo/lld/llvm-project/lld/MachO/Arch/ARM64.cpp:612
    #1 0x55d8e6daa514 in operator() /mnt/ssd/repo/lld/llvm-project/lld/MachO/Arch/ARM64.cpp:650

Differential Revision: https://reviews.llvm.org/D157027
  • Loading branch information
oontvoo committed Sep 11, 2023
1 parent 3e24a77 commit 595cd45
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lld/MachO/Arch/ARM64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,15 @@ void ARM64::applyOptimizationHints(uint8_t *outBuf, const ObjFile &obj) const {
addr < sectionAddr + section->getSize())
return true;

if (obj.sections.empty())
return false;
auto secIt = std::prev(llvm::upper_bound(
obj.sections, addr,
[](uint64_t off, const Section *sec) { return off < sec->addr; }));
const Section *sec = *secIt;

if (sec->subsections.empty())
return false;
auto subsecIt = std::prev(llvm::upper_bound(
sec->subsections, addr - sec->addr,
[](uint64_t off, Subsection subsec) { return off < subsec.offset; }));
Expand Down

0 comments on commit 595cd45

Please sign in to comment.