From 3828b88d869699936574d4d8efb154251e1bfeb1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 7 Apr 2016 15:50:23 +0000 Subject: [PATCH] Fix an use after free. Thanks to asan for pointing it out that OutputSections was being resized. llvm-svn: 265686 --- lld/ELF/Writer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index ff197ce..a760f55 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1061,7 +1061,9 @@ template void Writer::createSections() { // Scan relocations. This must be done after every symbol is declared so that // we can correctly decide if a dynamic relocation is needed. - for (OutputSectionBase *Sec : OutputSections) { + // Check size() each time to guard against .bss being created. + for (unsigned I = 0; I < OutputSections.size(); ++I) { + OutputSectionBase *Sec = OutputSections[I]; Sec->forEachInputSection([&](InputSectionBase *S) { if (auto *IS = dyn_cast>(S)) { // Set OutSecOff so that scanRelocs can use it. -- 2.7.4