[PATCH] [LLD] COFF: Fix unsafe memory access

Rui Ueyama ruiu at google.com
Thu Jun 18 13:06:04 PDT 2015


Hi pcc,

BitcodeFile::M is freed before the writer writes a result because of presence
of BitcodeFile::releaseModule(). So we cannot keep pointers to bitcode files
in symbols.

http://reviews.llvm.org/D10547

Files:
  COFF/InputFiles.cpp

Index: COFF/InputFiles.cpp
===================================================================
--- COFF/InputFiles.cpp
+++ COFF/InputFiles.cpp
@@ -256,12 +256,13 @@
     return make_error_code(LLDError::BrokenFile);
   }
 
+  llvm::BumpPtrStringSaver Saver(Alloc);
   for (unsigned I = 0, E = M->getSymbolCount(); I != E; ++I) {
     lto_symbol_attributes Attrs = M->getSymbolAttributes(I);
     if ((Attrs & LTO_SYMBOL_SCOPE_MASK) == LTO_SYMBOL_SCOPE_INTERNAL)
       continue;
 
-    StringRef SymName = M->getSymbolName(I);
+    StringRef SymName = Saver.save(M->getSymbolName(I));
     int SymbolDef = Attrs & LTO_SYMBOL_DEFINITION_MASK;
     if (SymbolDef == LTO_SYMBOL_DEFINITION_UNDEFINED) {
       SymbolBodies.push_back(new (Alloc) Undefined(SymName));

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10547.27954.patch
Type: text/x-patch
Size: 762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150618/83e732cb/attachment.bin>


More information about the llvm-commits mailing list