diff options
Diffstat (limited to 'libunwindstack/tests/MemoryRangeTest.cpp')
-rw-r--r-- | libunwindstack/tests/MemoryRangeTest.cpp | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/libunwindstack/tests/MemoryRangeTest.cpp b/libunwindstack/tests/MemoryRangeTest.cpp index d636ec497..ee5ba018b 100644 --- a/libunwindstack/tests/MemoryRangeTest.cpp +++ b/libunwindstack/tests/MemoryRangeTest.cpp @@ -17,6 +17,7 @@ #include <stdint.h> #include <string.h> +#include <memory> #include <vector> #include <gtest/gtest.h> @@ -65,35 +66,14 @@ TEST_F(MemoryRangeTest, read_near_limit) { ASSERT_FALSE(range.Read(1020, dst.data(), 5)); ASSERT_FALSE(range.Read(1024, dst.data(), 1)); ASSERT_FALSE(range.Read(1024, dst.data(), 1024)); -} - -TEST_F(MemoryRangeTest, read_string_past_end) { - std::string name("0123456789"); - memory_->SetMemory(0, name); - - // Verify a read past the range fails. - MemoryRange range(memory_, 0, 5); - std::string dst_name; - ASSERT_FALSE(range.ReadString(0, &dst_name)); -} - -TEST_F(MemoryRangeTest, read_string_to_end) { - std::string name("0123456789"); - memory_->SetMemory(30, name); - // Verify the range going to the end of the string works. - MemoryRange range(memory_, 30, 30 + name.size() + 1); - std::string dst_name; - ASSERT_TRUE(range.ReadString(0, &dst_name)); - ASSERT_EQ("0123456789", dst_name); + // Verify that reading up to the end works. + ASSERT_TRUE(range.Read(1020, dst.data(), 4)); } -TEST_F(MemoryRangeTest, read_string_fencepost) { - std::string name("0123456789"); - memory_->SetMemory(10, name); +TEST_F(MemoryRangeTest, read_overflow) { + std::vector<uint8_t> buffer(100); - // Verify the range set to one byte less than the end of the string fails. - MemoryRange range(memory_, 10, 10 + name.size()); - std::string dst_name; - ASSERT_FALSE(range.ReadString(0, &dst_name)); + std::unique_ptr<MemoryRange> overflow(new MemoryRange(new MemoryFakeAlwaysReadZero, 100, 200)); + ASSERT_FALSE(overflow->Read(UINT64_MAX - 10, buffer.data(), 100)); } |