teemperor created this revision.

When I added the Stream unit test (r338488), the build bots failed due to an 
out-of-
bound reads when passing an empty string to the PutCStringAsRawHex8 method.
In r338491 I removed the test case to fix the bots.

This patch fixes this in PutCStringAsRawHex8 by always checking for the 
terminating
null character in the given string (instead of skipping it the first time). It 
also re-adds the
test case I removed.


https://reviews.llvm.org/D50149

Files:
  source/Utility/Stream.cpp
  unittests/Utility/StreamTest.cpp


Index: unittests/Utility/StreamTest.cpp
===================================================================
--- unittests/Utility/StreamTest.cpp
+++ unittests/Utility/StreamTest.cpp
@@ -106,6 +106,9 @@
 }
 
 TEST_F(StreamTest, PutCStringAsRawHex8) {
+  s.PutCStringAsRawHex8("");
+  EXPECT_EQ("", TakeValue());
+
   s.PutCStringAsRawHex8("foobar");
   EXPECT_EQ("666f6f626172", TakeValue());
 
Index: source/Utility/Stream.cpp
===================================================================
--- source/Utility/Stream.cpp
+++ source/Utility/Stream.cpp
@@ -518,10 +518,10 @@
   size_t bytes_written = 0;
   bool binary_is_set = m_flags.Test(eBinary);
   m_flags.Clear(eBinary);
-  do {
+  while(*s) {
     bytes_written += _PutHex8(*s, false);
     ++s;
-  } while (*s);
+  }
   if (binary_is_set)
     m_flags.Set(eBinary);
   return bytes_written;


Index: unittests/Utility/StreamTest.cpp
===================================================================
--- unittests/Utility/StreamTest.cpp
+++ unittests/Utility/StreamTest.cpp
@@ -106,6 +106,9 @@
 }
 
 TEST_F(StreamTest, PutCStringAsRawHex8) {
+  s.PutCStringAsRawHex8("");
+  EXPECT_EQ("", TakeValue());
+
   s.PutCStringAsRawHex8("foobar");
   EXPECT_EQ("666f6f626172", TakeValue());
 
Index: source/Utility/Stream.cpp
===================================================================
--- source/Utility/Stream.cpp
+++ source/Utility/Stream.cpp
@@ -518,10 +518,10 @@
   size_t bytes_written = 0;
   bool binary_is_set = m_flags.Test(eBinary);
   m_flags.Clear(eBinary);
-  do {
+  while(*s) {
     bytes_written += _PutHex8(*s, false);
     ++s;
-  } while (*s);
+  }
   if (binary_is_set)
     m_flags.Set(eBinary);
   return bytes_written;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to