diff options
author | Raphael Isemann <teemperor@gmail.com> | 2018-08-01 21:07:18 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2018-08-01 21:07:18 +0000 |
commit | f4590de99244d3a3d21a5a1b0994005d1d655962 (patch) | |
tree | ad9beb015a11c8e471b50a5e69a488d6b545ea03 | |
parent | 9c66506604c7868c6e476df8410b8fcfe98ad975 (diff) | |
download | bcm5719-llvm-f4590de99244d3a3d21a5a1b0994005d1d655962.tar.gz bcm5719-llvm-f4590de99244d3a3d21a5a1b0994005d1d655962.zip |
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
llvm-svn: 338637
-rw-r--r-- | lldb/source/Utility/Stream.cpp | 4 | ||||
-rw-r--r-- | lldb/unittests/Utility/StreamTest.cpp | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp index cd0f2f56e0f..d65ff037791 100644 --- a/lldb/source/Utility/Stream.cpp +++ b/lldb/source/Utility/Stream.cpp @@ -518,10 +518,10 @@ size_t Stream::PutCStringAsRawHex8(const char *s) { 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; diff --git a/lldb/unittests/Utility/StreamTest.cpp b/lldb/unittests/Utility/StreamTest.cpp index bc77c196216..3210a6247f2 100644 --- a/lldb/unittests/Utility/StreamTest.cpp +++ b/lldb/unittests/Utility/StreamTest.cpp @@ -106,6 +106,9 @@ TEST_F(StreamTest, PutCharNull) { } TEST_F(StreamTest, PutCStringAsRawHex8) { + s.PutCStringAsRawHex8(""); + EXPECT_EQ("", TakeValue()); + s.PutCStringAsRawHex8("foobar"); EXPECT_EQ("666f6f626172", TakeValue()); |