From bcd7738b013accb1c32e0681c1271e9f30946bac Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Tue, 23 Oct 2018 14:09:48 +0100 Subject: Fix off by one error. Change-Id: I18a2d177f3212626b7091150f42dfe151e47570e --- libunwindstack/RegsInfo.h | 2 +- libunwindstack/tests/RegsInfoTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'libunwindstack') diff --git a/libunwindstack/RegsInfo.h b/libunwindstack/RegsInfo.h index e6dd33c..e445a91 100644 --- a/libunwindstack/RegsInfo.h +++ b/libunwindstack/RegsInfo.h @@ -41,7 +41,7 @@ struct RegsInfo { } inline AddressType* Save(uint32_t reg) { - if (reg > MAX_REGISTERS) { + if (reg >= MAX_REGISTERS) { // This should never happen since all currently supported // architectures have < 64 total registers. abort(); diff --git a/libunwindstack/tests/RegsInfoTest.cpp b/libunwindstack/tests/RegsInfoTest.cpp index 052b5bf..a6bc2c5 100644 --- a/libunwindstack/tests/RegsInfoTest.cpp +++ b/libunwindstack/tests/RegsInfoTest.cpp @@ -82,4 +82,11 @@ TEST(RegsInfoTest, all) { } } +TEST(RegsInfoTest, invalid_register) { + RegsImplFake regs(64); + RegsInfo info(®s); + + EXPECT_DEATH(info.Save(RegsInfo::MAX_REGISTERS), ""); +} + } // namespace unwindstack -- cgit v1.2.3