Fix an use after free.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 7 Apr 2016 15:50:23 +0000 (15:50 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 7 Apr 2016 15:50:23 +0000 (15:50 +0000)
Thanks to asan for pointing it out that OutputSections was being
resized.

llvm-svn: 265686

lld/ELF/Writer.cpp

index ff197ce..a760f55 100644 (file)
@@ -1061,7 +1061,9 @@ template <class ELFT> void Writer<ELFT>::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<ELFT> *Sec : OutputSections) {
+  // Check size() each time to guard against .bss being created.
+  for (unsigned I = 0; I < OutputSections.size(); ++I) {
+    OutputSectionBase<ELFT> *Sec = OutputSections[I];
     Sec->forEachInputSection([&](InputSectionBase<ELFT> *S) {
       if (auto *IS = dyn_cast<InputSection<ELFT>>(S)) {
         // Set OutSecOff so that scanRelocs can use it.