summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/MemoryRemoteTest.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/MemoryRemoteTest.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/MemoryRemoteTest.cpp')
-rw-r--r--libunwindstack/tests/MemoryRemoteTest.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/libunwindstack/tests/MemoryRemoteTest.cpp b/libunwindstack/tests/MemoryRemoteTest.cpp
index 7664c3e00..e48edf7e5 100644
--- a/libunwindstack/tests/MemoryRemoteTest.cpp
+++ b/libunwindstack/tests/MemoryRemoteTest.cpp
@@ -33,6 +33,8 @@
#include "Memory.h"
+#include "MemoryFake.h"
+
class MemoryRemoteTest : public ::testing::Test {
protected:
static uint64_t NanoTime() {
@@ -121,6 +123,9 @@ TEST_F(MemoryRemoteTest, read_fail) {
ASSERT_TRUE(remote.Read(reinterpret_cast<uint64_t>(src) + pagesize - 1, dst.data(), 1));
ASSERT_FALSE(remote.Read(reinterpret_cast<uint64_t>(src) + pagesize - 4, dst.data(), 8));
+ // Check overflow condition is caught properly.
+ ASSERT_FALSE(remote.Read(UINT64_MAX - 100, dst.data(), 200));
+
ASSERT_EQ(0, munmap(src, pagesize));
ASSERT_TRUE(Detach(pid));
@@ -128,6 +133,14 @@ TEST_F(MemoryRemoteTest, read_fail) {
kill(pid, SIGKILL);
}
+TEST_F(MemoryRemoteTest, read_overflow) {
+ MemoryFakeRemote remote;
+
+ // Check overflow condition is caught properly.
+ std::vector<uint8_t> dst(200);
+ ASSERT_FALSE(remote.Read(UINT64_MAX - 100, dst.data(), 200));
+}
+
TEST_F(MemoryRemoteTest, read_illegal) {
pid_t pid;
if ((pid = fork()) == 0) {