From a39aaf91ebec78f59a371e356523b10453efb4b2 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Thu, 20 Dec 2018 08:40:58 -0800 Subject: [PATCH] Remove CHECK in AdjustEncodedValue. The CHECK(encoding != DW_EH_PE_aligned) can trip given the right arguments. This check isn't necessary, since the code will return false in that case. Add new unit test that tries all values to make sure no CHECK fires. Bug: 120968571 Test: Passes new unit test, and passes fuzzing that failed before. Change-Id: I062bcd18508c75cd3a4ca9dd12f922e25aafda8a --- libunwindstack/DwarfMemory.cpp | 1 - libunwindstack/tests/DwarfMemoryTest.cpp | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libunwindstack/DwarfMemory.cpp b/libunwindstack/DwarfMemory.cpp index 6ffdc0de1..b5059007c 100644 --- a/libunwindstack/DwarfMemory.cpp +++ b/libunwindstack/DwarfMemory.cpp @@ -104,7 +104,6 @@ size_t DwarfMemory::GetEncodedSize(uint8_t encoding) { bool DwarfMemory::AdjustEncodedValue(uint8_t encoding, uint64_t* value) { CHECK((encoding & 0x0f) == 0); - CHECK(encoding != DW_EH_PE_aligned); // Handle the encoding. switch (encoding) { diff --git a/libunwindstack/tests/DwarfMemoryTest.cpp b/libunwindstack/tests/DwarfMemoryTest.cpp index f12d2fe3e..650e965b2 100644 --- a/libunwindstack/tests/DwarfMemoryTest.cpp +++ b/libunwindstack/tests/DwarfMemoryTest.cpp @@ -54,6 +54,8 @@ class DwarfMemoryTest : public ::testing::Test { void ReadEncodedValue_overflow(); template void ReadEncodedValue_high_bit_set(); + template + void ReadEncodedValue_all(); MemoryFake memory_; std::unique_ptr dwarf_mem_; @@ -457,6 +459,27 @@ TEST_F(DwarfMemoryTest, ReadEncodedValue_high_bit_set_uint64_t) { ReadEncodedValue_high_bit_set(); } +template +void DwarfMemoryTest::ReadEncodedValue_all() { + MemoryFakeAlwaysReadZero memory; + DwarfMemory dwarf_mem(&memory); + + for (size_t i = 0; i <= 0xff; i++) { + uint64_t value; + if (dwarf_mem.ReadEncodedValue(static_cast(i), &value)) { + ASSERT_EQ(0U, value); + } + } +} + +TEST_F(DwarfMemoryTest, ReadEncodedValue_all_uint32_t) { + ReadEncodedValue_all(); +} + +TEST_F(DwarfMemoryTest, ReadEncodedValue_all_uint64_t) { + ReadEncodedValue_all(); +} + TEST_F(DwarfMemoryTest, AdjustEncodedValue_absptr) { uint64_t value = 0x1234; ASSERT_TRUE(dwarf_mem_->AdjustEncodedValue(0x00, &value));