[lld] r265686 - Fix an use after free.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 08:50:24 PDT 2016


Author: rafael
Date: Thu Apr  7 10:50:23 2016
New Revision: 265686

URL: http://llvm.org/viewvc/llvm-project?rev=265686&view=rev
Log:
Fix an use after free.

Thanks to asan for pointing it out that OutputSections was being
resized.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=265686&r1=265685&r2=265686&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Apr  7 10:50:23 2016
@@ -1061,7 +1061,9 @@ template <class ELFT> void Writer<ELFT>:
 
   // 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.




More information about the llvm-commits mailing list