Safety fix for GetCharPointer

Uses IsValidNullTerminatedString from #19103 by Kethen
This commit is contained in:
Henrik Rydgård 2024-05-05 12:08:41 +02:00
parent 9d0c127961
commit 85f8fd0bdb

View file

@ -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.