[llvm-commits] [llvm] r133867 - /llvm/trunk/include/llvm/Bitcode/BitstreamReader.h

Nick Lewycky nicholas at mxc.ca
Sat Jun 25 10:08:50 PDT 2011


Author: nicholas
Date: Sat Jun 25 12:08:50 2011
New Revision: 133867

URL: http://llvm.org/viewvc/llvm-project?rev=133867&view=rev
Log:
Enhance the sanity check for block sizes; check that the resulting pointer is
pointing to the range [first character, last character] instead of just not
after the last character. Patch by Yan Ivnitskiy!

Modified:
    llvm/trunk/include/llvm/Bitcode/BitstreamReader.h

Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=133867&r1=133866&r2=133867&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Sat Jun 25 12:08:50 2011
@@ -375,10 +375,12 @@
 
     // Check that the block wasn't partially defined, and that the offset isn't
     // bogus.
-    if (AtEndOfStream() || NextChar+NumWords*4 > BitStream->getLastChar())
+    const unsigned char *const SkipTo = NextChar + NumWords*4;
+    if (AtEndOfStream() || SkipTo > BitStream->getLastChar() ||
+                           SkipTo < BitStream->getFirstChar())
       return true;
 
-    NextChar += NumWords*4;
+    NextChar = SkipTo;
     return false;
   }
 





More information about the llvm-commits mailing list