summaryrefslogtreecommitdiffstats
path: root/lld/lib/Passes/LayoutPass.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2013-10-02 23:21:07 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2013-10-02 23:21:07 +0000
commitc80f88a94e965cc4bf52588cfc105376b2fee35a (patch)
treef5b512c6c1b55102705b1402bae0691d71bb65e4 /lld/lib/Passes/LayoutPass.cpp
parentc366504546a95d34255e45fa340cd8563158e720 (diff)
downloadbcm5719-llvm-c80f88a94e965cc4bf52588cfc105376b2fee35a.tar.gz
bcm5719-llvm-c80f88a94e965cc4bf52588cfc105376b2fee35a.zip
[Core] Fix heap overflow in LayoutPass.
Found this with asan. Code assumes that find doesn't return end, thus if both atoms didn't have followon roots it would still compare their positions. llvm-svn: 191865
Diffstat (limited to 'lld/lib/Passes/LayoutPass.cpp')
-rw-r--r--lld/lib/Passes/LayoutPass.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/lld/lib/Passes/LayoutPass.cpp b/lld/lib/Passes/LayoutPass.cpp
index b116496e036..c4c8fb9c33e 100644
--- a/lld/lib/Passes/LayoutPass.cpp
+++ b/lld/lib/Passes/LayoutPass.cpp
@@ -56,10 +56,12 @@ bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
// Sort atoms by their ordinal overrides only if they fall in the same
// chain.
- const DefinedAtom *leftAtom = _layout._followOnRoots.find(left)->second;
- const DefinedAtom *rightAtom = _layout._followOnRoots.find(right)->second;
+ auto leftAtom = _layout._followOnRoots.find(left);
+ auto rightAtom = _layout._followOnRoots.find(right);
- if (leftAtom == rightAtom) {
+ if (leftAtom != _layout._followOnRoots.end() &&
+ rightAtom != _layout._followOnRoots.end() &&
+ leftAtom->second == rightAtom->second) {
if ((lPos != end) && (rPos != end)) {
return lPos->second < rPos->second;
}
OpenPOWER on IntegriCloud