From: Rafael Espindola Date: Thu, 7 Apr 2016 15:50:23 +0000 (+0000) Subject: Fix an use after free. X-Git-Tag: llvmorg-3.9.0-rc1~9727 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3828b88d869699936574d4d8efb154251e1bfeb1;p=platform%2Fupstream%2Fllvm.git Fix an use after free. Thanks to asan for pointing it out that OutputSections was being resized. llvm-svn: 265686 --- 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.