From 85f8fd0bdbcfd249536c25aed69da52bd903b79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 5 May 2024 12:08:41 +0200 Subject: [PATCH] Safety fix for GetCharPointer Uses IsValidNullTerminatedString from #19103 by Kethen --- Core/MemMap.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/MemMap.h b/Core/MemMap.h index 56acfe823b..247d4d3478 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -270,16 +270,6 @@ inline bool IsKernelAndNotVolatileAddress(const u32 address) { bool IsScratchpadAddress(const u32 address); -// Used for auto-converted char * parameters, which can sometimes legitimately be null - -// so we don't want to get caught in GetPointer's crash reporting. -inline const char* GetCharPointer(const u32 address) { - if (address) { - return (const char *)GetPointer(address); - } else { - return nullptr; - } -} - inline const char *GetCharPointerUnchecked(const u32 address) { return (const char *)GetPointerUnchecked(address); } @@ -351,6 +341,16 @@ inline bool IsValidRange(const u32 address, const u32 size) { return ValidSize(address, size) == size; } +// Used for auto-converted char * parameters, which can sometimes legitimately be null - +// so we don't want to get caught in GetPointer's crash reporting. +inline const char *GetCharPointer(const u32 address) { + if (address && IsValidNullTerminatedString(address)) { + return GetCharPointerUnchecked(address); + } else { + return nullptr; + } +} + } // namespace Memory // Avoiding a global include for NotifyMemInfo.