From 32921acc5a9297705e6c406413af452b47eaa971 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 23 Aug 2020 14:03:36 +1000 Subject: [PATCH] Timers: Don't read out of bounds for invalid address --- src/core/timers.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/timers.cpp b/src/core/timers.cpp index 0fad8957c..fc7a06396 100644 --- a/src/core/timers.cpp +++ b/src/core/timers.cpp @@ -177,6 +177,11 @@ u32 Timers::ReadRegister(u32 offset) { const u32 timer_index = (offset >> 4) & u32(0x03); const u32 port_offset = offset & u32(0x0F); + if (timer_index >= 3) + { + Log_ErrorPrintf("Timer read out of range: offset 0x%02X", offset); + return UINT32_C(0xFFFFFFFF); + } CounterState& cs = m_states[timer_index]; @@ -226,6 +231,11 @@ void Timers::WriteRegister(u32 offset, u32 value) { const u32 timer_index = (offset >> 4) & u32(0x03); const u32 port_offset = offset & u32(0x0F); + if (timer_index >= 3) + { + Log_ErrorPrintf("Timer write out of range: offset 0x%02X value 0x%08X", offset, value); + return; + } CounterState& cs = m_states[timer_index];