[llvm] r273710 - [CodeView] Healthy paranoia around strings

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 12:34:42 PDT 2016


Author: majnemer
Date: Fri Jun 24 14:34:41 2016
New Revision: 273710

URL: http://llvm.org/viewvc/llvm-project?rev=273710&view=rev
Log:
[CodeView] Healthy paranoia around strings

Make sure strings don't get too big for a record, truncate them if
need-be.

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/ListRecordBuilder.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordBuilder.h
    llvm/trunk/lib/DebugInfo/CodeView/ListRecordBuilder.cpp
    llvm/trunk/lib/DebugInfo/CodeView/TypeRecordBuilder.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/ListRecordBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/ListRecordBuilder.h?rev=273710&r1=273709&r2=273710&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/ListRecordBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/ListRecordBuilder.h Fri Jun 24 14:34:41 2016
@@ -50,7 +50,7 @@ private:
     return ContinuationOffsets.empty() ? 0 : ContinuationOffsets.back();
   }
   size_t getLastContinuationEnd() const { return Builder.size(); }
-  unsigned getLastContinuationSize() const {
+  size_t getLastContinuationSize() const {
     return getLastContinuationEnd() - getLastContinuationStart();
   }
 

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordBuilder.h?rev=273710&r1=273709&r2=273710&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecordBuilder.h Fri Jun 24 14:34:41 2016
@@ -40,7 +40,6 @@ public:
   void writeEncodedInteger(int64_t Value);
   void writeEncodedSignedInteger(int64_t Value);
   void writeEncodedUnsignedInteger(uint64_t Value);
-  void writeNullTerminatedString(const char *Value);
   void writeNullTerminatedString(StringRef Value);
   void writeGuid(StringRef Guid);
   void writeBytes(StringRef Value) { Stream << Value; }

Modified: llvm/trunk/lib/DebugInfo/CodeView/ListRecordBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/ListRecordBuilder.cpp?rev=273710&r1=273709&r2=273710&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/ListRecordBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/ListRecordBuilder.cpp Fri Jun 24 14:34:41 2016
@@ -49,8 +49,10 @@ void ListRecordBuilder::finishSubRecord(
   // back up and insert a continuation record, sliding the current subrecord
   // down.
   if (getLastContinuationSize() > 65535 - 8) {
+    assert(SubrecordStart != 0 && "can't slide from the start!");
     SmallString<128> SubrecordCopy(
         Builder.str().slice(SubrecordStart, Builder.size()));
+    assert(SubrecordCopy.size() < 65530 && "subrecord is too large to slide!");
     Builder.truncate(SubrecordStart);
 
     // Write a placeholder continuation record.

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeRecordBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeRecordBuilder.cpp?rev=273710&r1=273709&r2=273710&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeRecordBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeRecordBuilder.cpp Fri Jun 24 14:34:41 2016
@@ -91,15 +91,10 @@ void TypeRecordBuilder::writeEncodedUnsi
   }
 }
 
-void TypeRecordBuilder::writeNullTerminatedString(const char *Value) {
-  assert(Value != nullptr);
-
-  size_t Length = strlen(Value);
-  Stream.write(Value, Length);
-  writeUInt8(0);
-}
-
 void TypeRecordBuilder::writeNullTerminatedString(StringRef Value) {
+  // Microsoft's linker seems to have trouble with symbol names longer than
+  // 0xffd8 bytes.
+  Value = Value.substr(0, 0xffd8);
   Stream.write(Value.data(), Value.size());
   writeUInt8(0);
 }




More information about the llvm-commits mailing list