[Lldb-commits] [lldb] r338637 - Fix out-of-bounds read in Stream::PutCStringAsRawHex8

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 1 14:07:19 PDT 2018


Author: teemperor
Date: Wed Aug  1 14:07:18 2018
New Revision: 338637

URL: http://llvm.org/viewvc/llvm-project?rev=338637&view=rev
Log:
Fix out-of-bounds read in Stream::PutCStringAsRawHex8

Summary:
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.

Reviewers: vsk

Reviewed By: vsk

Subscribers: vsk, lldb-commits

Differential Revision: https://reviews.llvm.org/D50149

Modified:
    lldb/trunk/source/Utility/Stream.cpp
    lldb/trunk/unittests/Utility/StreamTest.cpp

Modified: lldb/trunk/source/Utility/Stream.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Stream.cpp?rev=338637&r1=338636&r2=338637&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Stream.cpp (original)
+++ lldb/trunk/source/Utility/Stream.cpp Wed Aug  1 14:07:18 2018
@@ -518,10 +518,10 @@ size_t Stream::PutCStringAsRawHex8(const
   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;

Modified: lldb/trunk/unittests/Utility/StreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StreamTest.cpp?rev=338637&r1=338636&r2=338637&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/StreamTest.cpp (original)
+++ lldb/trunk/unittests/Utility/StreamTest.cpp Wed Aug  1 14:07:18 2018
@@ -106,6 +106,9 @@ TEST_F(StreamTest, PutCharNull) {
 }
 
 TEST_F(StreamTest, PutCStringAsRawHex8) {
+  s.PutCStringAsRawHex8("");
+  EXPECT_EQ("", TakeValue());
+
   s.PutCStringAsRawHex8("foobar");
   EXPECT_EQ("666f6f626172", TakeValue());
 




More information about the lldb-commits mailing list