summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/MemoryLocalTest.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-04-03 12:39:47 -0700
committerChristopher Ferris <cferris@google.com>2017-04-03 18:36:33 -0700
commitf447c8eb205d899085968a0a8dfae861ef56a589 (patch)
treeb7cbe68673663760db5330d33c2fd75d2651fcbe /libunwindstack/tests/MemoryLocalTest.cpp
parent8aae1b158ad45bd3a7eeace9558ee7390b12fa94 (diff)
Add overflow checks in Memory objects.
Also change one of the reads to be explicitly ReadField instead of an overloaded Read function. Bug: 23762183 Test: Passes new unit tests. Change-Id: Id848f7b632f67df0c5b7318d9e588942cfd2099a
Diffstat (limited to 'libunwindstack/tests/MemoryLocalTest.cpp')
-rw-r--r--libunwindstack/tests/MemoryLocalTest.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/libunwindstack/tests/MemoryLocalTest.cpp b/libunwindstack/tests/MemoryLocalTest.cpp
index 0ba5f1c37..ab999dafc 100644
--- a/libunwindstack/tests/MemoryLocalTest.cpp
+++ b/libunwindstack/tests/MemoryLocalTest.cpp
@@ -47,29 +47,20 @@ TEST(MemoryLocalTest, read) {
}
}
-TEST(MemoryLocalTest, read_string) {
- std::string name("string_in_memory");
-
+TEST(MemoryLocalTest, read_illegal) {
MemoryLocal local;
- std::vector<uint8_t> dst(1024);
- std::string dst_name;
- ASSERT_TRUE(local.ReadString(reinterpret_cast<uint64_t>(name.c_str()), &dst_name));
- ASSERT_EQ("string_in_memory", dst_name);
-
- ASSERT_TRUE(local.ReadString(reinterpret_cast<uint64_t>(&name[7]), &dst_name));
- ASSERT_EQ("in_memory", dst_name);
-
- ASSERT_TRUE(local.ReadString(reinterpret_cast<uint64_t>(&name[7]), &dst_name, 10));
- ASSERT_EQ("in_memory", dst_name);
-
- ASSERT_FALSE(local.ReadString(reinterpret_cast<uint64_t>(&name[7]), &dst_name, 9));
+ std::vector<uint8_t> dst(100);
+ ASSERT_FALSE(local.Read(0, dst.data(), 1));
+ ASSERT_FALSE(local.Read(0, dst.data(), 100));
}
-TEST(MemoryLocalTest, read_illegal) {
+TEST(MemoryLocalTest, read_overflow) {
MemoryLocal local;
+ // On 32 bit this test doesn't necessarily cause an overflow. The 64 bit
+ // version will always go through the overflow check.
std::vector<uint8_t> dst(100);
- ASSERT_FALSE(local.Read(0, dst.data(), 1));
- ASSERT_FALSE(local.Read(0, dst.data(), 100));
+ uint64_t value;
+ ASSERT_FALSE(local.Read(reinterpret_cast<uint64_t>(&value), dst.data(), SIZE_MAX));
}