[llvm-commits] [llvm] r104334 - /llvm/trunk/include/llvm/MC/MCObjectWriter.h

Nathan Jeffords blunted2night at gmail.com
Fri May 21 11:23:56 PDT 2010


Author: njeffords
Date: Fri May 21 13:23:56 2010
New Revision: 104334

URL: http://llvm.org/viewvc/llvm-project?rev=104334&view=rev
Log:
added an assertion to MCObjectWriter::WriteBytes to catch misuse of the ZeroFillSize parameter

If the size of the string is greater than the zero fill size, the function will attempt to write a very large string of zeros to the object file (~4GB on 32 bit platforms). This assertion will catch the scenario and crash the program before the write occurs.

Modified:
    llvm/trunk/include/llvm/MC/MCObjectWriter.h

Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=104334&r1=104333&r2=104334&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Fri May 21 13:23:56 2010
@@ -152,6 +152,8 @@
   }
 
   void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) {
+    assert((ZeroFillSize == 0 || Str.size () <= ZeroFillSize) &&
+      "data size greater than fill size, unexpected large write will occur");
     OS << Str;
     if (ZeroFillSize)
       WriteZeros(ZeroFillSize - Str.size());





More information about the llvm-commits mailing list