Merge "Fix dangling pointer issue in LocalUpdatbleMaps" into rvc-dev am: 64021d834a

Change-Id: I23e337eb2b6705e07b2d93f3561285923544d4f0
This commit is contained in:
Christopher Ferris 2020-05-02 16:36:18 +00:00 committed by Automerger Merge Worker
commit 2273266944
2 changed files with 101 additions and 0 deletions

View file

@ -159,6 +159,8 @@ bool LocalUpdatableMaps::Reparse() {
search_map_idx = old_map_idx + 1;
if (new_map_idx + 1 < maps_.size()) {
maps_[new_map_idx + 1]->prev_map = info.get();
maps_[new_map_idx + 1]->prev_real_map =
info->IsBlank() ? info->prev_real_map : info.get();
}
maps_[new_map_idx] = nullptr;
total_entries--;

View file

@ -271,4 +271,103 @@ TEST_F(LocalUpdatableMapsTest, all_new_maps) {
EXPECT_TRUE(map_info->name.empty());
}
TEST_F(LocalUpdatableMapsTest, add_map_prev_name_updated) {
TemporaryFile tf;
ASSERT_TRUE(
android::base::WriteStringToFile("3000-4000 rwxp 00000 00:00 0\n"
"8000-9000 r-xp 00000 00:00 0\n"
"9000-a000 r-xp 00000 00:00 0\n",
tf.path));
maps_.TestSetMapsFile(tf.path);
ASSERT_TRUE(maps_.Reparse());
ASSERT_EQ(3U, maps_.Total());
MapInfo* map_info = maps_.Get(2);
ASSERT_TRUE(map_info != nullptr);
EXPECT_EQ(0x9000U, map_info->start);
EXPECT_EQ(0xA000U, map_info->end);
EXPECT_EQ(0U, map_info->offset);
EXPECT_EQ(PROT_READ | PROT_EXEC, map_info->flags);
EXPECT_TRUE(map_info->name.empty());
EXPECT_EQ(maps_.Get(1), map_info->prev_map);
}
TEST_F(LocalUpdatableMapsTest, add_map_prev_real_name_updated) {
TemporaryFile tf;
ASSERT_TRUE(
android::base::WriteStringToFile("3000-4000 r-xp 00000 00:00 0 /fake/lib.so\n"
"4000-5000 ---p 00000 00:00 0\n"
"7000-8000 r-xp 00000 00:00 0 /fake/lib1.so\n"
"8000-9000 ---p 00000 00:00 0\n",
tf.path));
maps_.TestSetMapsFile(tf.path);
ASSERT_TRUE(maps_.Reparse());
ASSERT_EQ(4U, maps_.Total());
MapInfo* map_info = maps_.Get(2);
ASSERT_TRUE(map_info != nullptr);
EXPECT_EQ(0x7000U, map_info->start);
EXPECT_EQ(0x8000U, map_info->end);
EXPECT_EQ(0U, map_info->offset);
EXPECT_EQ(PROT_READ | PROT_EXEC, map_info->flags);
EXPECT_EQ(maps_.Get(0), map_info->prev_real_map);
EXPECT_EQ(maps_.Get(1), map_info->prev_map);
EXPECT_EQ("/fake/lib1.so", map_info->name);
map_info = maps_.Get(3);
ASSERT_TRUE(map_info != nullptr);
EXPECT_EQ(0x8000U, map_info->start);
EXPECT_EQ(0x9000U, map_info->end);
EXPECT_EQ(0U, map_info->offset);
EXPECT_TRUE(map_info->IsBlank());
EXPECT_EQ(maps_.Get(2), map_info->prev_real_map);
EXPECT_EQ(maps_.Get(2), map_info->prev_map);
EXPECT_TRUE(map_info->name.empty());
ASSERT_TRUE(
android::base::WriteStringToFile("3000-4000 r-xp 00000 00:00 0 /fake/lib.so\n"
"4000-5000 ---p 00000 00:00 0\n"
"7000-8000 r-xp 00000 00:00 0 /fake/lib1.so\n"
"8000-9000 ---p 00000 00:00 0\n"
"9000-a000 r-xp 00000 00:00 0 /fake/lib2.so\n"
"a000-b000 r-xp 00000 00:00 0 /fake/lib3.so\n",
tf.path));
maps_.TestSetMapsFile(tf.path);
ASSERT_TRUE(maps_.Reparse());
ASSERT_EQ(6U, maps_.Total());
map_info = maps_.Get(2);
ASSERT_TRUE(map_info != nullptr);
EXPECT_EQ(0x7000U, map_info->start);
EXPECT_EQ(0x8000U, map_info->end);
EXPECT_EQ(0U, map_info->offset);
EXPECT_EQ(PROT_READ | PROT_EXEC, map_info->flags);
EXPECT_EQ("/fake/lib1.so", map_info->name);
EXPECT_EQ(maps_.Get(1), map_info->prev_map);
EXPECT_EQ(maps_.Get(0), map_info->prev_real_map);
map_info = maps_.Get(4);
ASSERT_TRUE(map_info != nullptr);
EXPECT_EQ(0x9000U, map_info->start);
EXPECT_EQ(0xA000U, map_info->end);
EXPECT_EQ(0U, map_info->offset);
EXPECT_EQ(PROT_READ | PROT_EXEC, map_info->flags);
EXPECT_EQ("/fake/lib2.so", map_info->name);
EXPECT_EQ(maps_.Get(3), map_info->prev_map);
EXPECT_EQ(maps_.Get(2), map_info->prev_real_map);
map_info = maps_.Get(5);
ASSERT_TRUE(map_info != nullptr);
EXPECT_EQ(0xA000U, map_info->start);
EXPECT_EQ(0xB000U, map_info->end);
EXPECT_EQ(0U, map_info->offset);
EXPECT_EQ(PROT_READ | PROT_EXEC, map_info->flags);
EXPECT_EQ("/fake/lib3.so", map_info->name);
EXPECT_EQ(maps_.Get(4), map_info->prev_map);
EXPECT_EQ(maps_.Get(4), map_info->prev_real_map);
}
} // namespace unwindstack