[lld] r229749 - Fix use-after-free bug identified by the Address Sanitizer

Greg Fitzgerald garious at gmail.com
Wed Feb 18 13:54:33 PST 2015


Author: garious
Date: Wed Feb 18 15:54:32 2015
New Revision: 229749

URL: http://llvm.org/viewvc/llvm-project?rev=229749&view=rev
Log:
Fix use-after-free bug identified by the Address Sanitizer

atomContent's memory is freed at the end of the stack frame,
but it is referenced by the atom pushed into _definedAtoms.

Differential Revision: http://reviews.llvm.org/D7732

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=229749&r1=229748&r2=229749&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Wed Feb 18 15:54:32 2015
@@ -985,12 +985,10 @@ std::error_code FileCOFF::maybeCreateSXD
   if (sxdata.empty())
     return std::error_code();
 
-  std::vector<uint8_t> atomContent =
-      *new (_alloc) std::vector<uint8_t>((size_t)sxdata.size());
   auto *atom = new (_alloc) COFFDefinedAtom(
       *this, "", ".sxdata", Atom::scopeTranslationUnit, DefinedAtom::typeData,
       false /*isComdat*/, DefinedAtom::permR__, DefinedAtom::mergeNo,
-      atomContent, _ordinal++);
+      sxdata, _ordinal++);
 
   const ulittle32_t *symbolIndex =
       reinterpret_cast<const ulittle32_t *>(sxdata.data());





More information about the llvm-commits mailing list