From 668b8d60c8ebeeb0a60a0e3b386f79325cbafbbf Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 13 Dec 2020 06:08:45 +0100 Subject: [PATCH] Core/AddressSpace: Return null accessors when no game is running to prevent out-of-bounds memory accesses. --- Source/Core/Core/HW/AddressSpace.cpp | 10 ++++++++++ Source/Core/Core/HW/AddressSpace.h | 1 + Source/Core/Core/HW/HW.cpp | 1 + 3 files changed, 12 insertions(+) diff --git a/Source/Core/Core/HW/AddressSpace.cpp b/Source/Core/Core/HW/AddressSpace.cpp index 0506db7687..af60db1d04 100644 --- a/Source/Core/Core/HW/AddressSpace.cpp +++ b/Source/Core/Core/HW/AddressSpace.cpp @@ -374,9 +374,13 @@ static SmallBlockAccessors s_fake_address_space_accessors; static CompositeAddressSpaceAccessors s_physical_address_space_accessors_gcn; static CompositeAddressSpaceAccessors s_physical_address_space_accessors_wii; static NullAccessors s_null_accessors; +static bool s_initialized = false; Accessors* GetAccessors(Type address_space) { + if (!s_initialized) + return &s_null_accessors; + // default to effective switch (address_space) { @@ -420,6 +424,12 @@ void Init() s_physical_address_space_accessors_gcn = {{0x00000000, &s_mem1_address_space_accessors}}; s_physical_address_space_accessors_wii = {{0x00000000, &s_mem1_address_space_accessors}, {0x10000000, &s_mem2_address_space_accessors}}; + s_initialized = true; +} + +void Shutdown() +{ + s_initialized = false; } } // namespace AddressSpace diff --git a/Source/Core/Core/HW/AddressSpace.h b/Source/Core/Core/HW/AddressSpace.h index c1ed71ed20..0df5c1ee40 100644 --- a/Source/Core/Core/HW/AddressSpace.h +++ b/Source/Core/Core/HW/AddressSpace.h @@ -48,5 +48,6 @@ struct Accessors Accessors* GetAccessors(Type address_space); void Init(); +void Shutdown(); } // namespace AddressSpace diff --git a/Source/Core/Core/HW/HW.cpp b/Source/Core/Core/HW/HW.cpp index 3fcaebe863..654164d960 100644 --- a/Source/Core/Core/HW/HW.cpp +++ b/Source/Core/Core/HW/HW.cpp @@ -70,6 +70,7 @@ void Shutdown() CPU::Shutdown(); DVDInterface::Shutdown(); DSP::Shutdown(); + AddressSpace::Shutdown(); Memory::Shutdown(); ExpansionInterface::Shutdown(); SerialInterface::Shutdown();