[llvm-commits] [llvm-gcc-4.2] r74056 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Chris Lattner sabre at nondot.org
Tue Jun 23 20:59:03 PDT 2009


Author: lattner
Date: Tue Jun 23 22:59:03 2009
New Revision: 74056

URL: http://llvm.org/viewvc/llvm-project?rev=74056&view=rev
Log:
Fix an array over-read problem that would sometimes manifest as a crash (when overreading
a string would point to invalid data.  The issue here is that TREE_STRING_LENGTH returns
the length in bytes of a string, not in characters.  This is different for a wide string.

In cases when this didn't crash, this bug would not manifest as a codegen problem, because
the code right below the overread would trim the length of the generated vector to the 
right length.

This fixes rdar://6961178

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=74056&r1=74055&r2=74056&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Jun 23 22:59:03 2009
@@ -6642,13 +6642,17 @@
     for (unsigned i = 0; i != Len; ++i)
       Elts.push_back(ConstantInt::get(Type::Int8Ty, InStr[i]));
   } else if (ElTy == Type::Int16Ty) {
+    assert((Len&1) == 0 &&
+           "Length in bytes should be a multiple of element size");
     const unsigned short *InStr =
       (const unsigned short *)TREE_STRING_POINTER(exp);
-    for (unsigned i = 0; i != Len; ++i)
+    for (unsigned i = 0; i != Len/2; ++i)
       Elts.push_back(ConstantInt::get(Type::Int16Ty, InStr[i]));
   } else if (ElTy == Type::Int32Ty) {
+    assert((Len&3) == 0 &&
+           "Length in bytes should be a multiple of element size");
     const unsigned *InStr = (const unsigned *)TREE_STRING_POINTER(exp);
-    for (unsigned i = 0; i != Len; ++i)
+    for (unsigned i = 0; i != Len/4; ++i)
       Elts.push_back(ConstantInt::get(Type::Int32Ty, InStr[i]));
   } else {
     assert(0 && "Unknown character type!");





More information about the llvm-commits mailing list