[PATCH] D157027: [lld-macho][nfc]Add bounds check before attempting to dereferencing iterators.
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 13:15:33 PDT 2023
oontvoo created this revision.
Herald added a subscriber: kristof.beyls.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157027
Files:
lld/MachO/Arch/ARM64.cpp
Index: lld/MachO/Arch/ARM64.cpp
===================================================================
--- lld/MachO/Arch/ARM64.cpp
+++ lld/MachO/Arch/ARM64.cpp
@@ -605,11 +605,18 @@
auto secIt = std::prev(llvm::upper_bound(
obj.sections, addr,
[](uint64_t off, const Section *sec) { return off < sec->addr; }));
+ if (secIt < obj.sections.begin() || secIt > obj.sections.end() ||
+ secIt == obj.sections.end())
+ return false;
const Section *sec = *secIt;
auto subsecIt = std::prev(llvm::upper_bound(
sec->subsections, addr - sec->addr,
[](uint64_t off, Subsection subsec) { return off < subsec.offset; }));
+ if (subsecIt < sec->subsections.begin() ||
+ subsecIt > sec->subsections.end() || subsecIt == sec->subsections.end())
+ return false;
+
const Subsection &subsec = *subsecIt;
const ConcatInputSection *isec =
dyn_cast_or_null<ConcatInputSection>(subsec.isec);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157027.546983.patch
Type: text/x-patch
Size: 968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230803/f276faaf/attachment.bin>
More information about the llvm-commits
mailing list