From d77f361c01e0ad36218d5f4265e1219b6c1fb983 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Wed, 29 Oct 2014 01:16:18 +1300 Subject: [PATCH] Add range checking to CopyTo/FromEmu so it won't segfault. --- Source/Core/Core/HW/Memmap.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index f3f95e4a1c..cd9e2484bc 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -219,13 +219,30 @@ u32 Read_Instruction(const u32 em_address) return inst.hex; } +static inline bool ValidCopyRange(u32 address, size_t size) +{ + return (GetPointer(address) != nullptr && + GetPointer(address + u32(size)) != nullptr && + size < EXRAM_SIZE); // Make sure we don't have a range spanning seperate 2 banks +} + void CopyFromEmu(void* data, u32 address, size_t size) { + if (!ValidCopyRange(address, size)) + { + PanicAlert("Invalid range in CopyFromEmu. %lx bytes from 0x%08x", size, address); + return; + } memcpy(data, GetPointer(address), size); } void CopyToEmu(u32 address, const void* data, size_t size) { + if (!ValidCopyRange(address, size)) + { + PanicAlert("Invalid range in CopyToEmu. %lx bytes to 0x%08x", size, address); + return; + } memcpy(GetPointer(address), data, size); }