[llvm] r207621 - raw_ostream::operator<<(StringRef): Avoid potential overflow in pointer arithmetic.

NAKAMURA Takumi geek4civic at gmail.com
Wed Apr 30 02:33:50 PDT 2014


Author: chapuni
Date: Wed Apr 30 04:33:50 2014
New Revision: 207621

URL: http://llvm.org/viewvc/llvm-project?rev=207621&view=rev
Log:
raw_ostream::operator<<(StringRef): Avoid potential overflow in pointer arithmetic.

(OutBufCur + Size) might overflow if Size were large. For example on i686-linux,

  OutBufCur: 0xFFFDF27D
  OutBufEnd: 0xFFFDF370
  Size:      0x0002BF20 (180,000)

It caused flaky error in MC/COFF/section-name-encoding.s.

Modified:
    llvm/trunk/include/llvm/Support/raw_ostream.h

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=207621&r1=207620&r2=207621&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Wed Apr 30 04:33:50 2014
@@ -162,7 +162,7 @@ public:
     size_t Size = Str.size();
 
     // Make sure we can use the fast path.
-    if (OutBufCur+Size > OutBufEnd)
+    if (Size > (size_t)(OutBufEnd - OutBufCur))
       return write(Str.data(), Size);
 
     memcpy(OutBufCur, Str.data(), Size);





More information about the llvm-commits mailing list