From 5a95c5dd14444f60eb7e36b3a941e469e5e638ff Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sun, 1 Sep 2024 19:35:56 -0700 Subject: [PATCH] CachedInterpreterEmitter: Fix `std::memcpy` UB I wasn't aware that even with a size of zero, it's still not safe to pass a nullptr to `std::memcpy`. When `CachedInterpreterEmitter::PoisonCallback` is written, UB is happening. --- .../Core/PowerPC/CachedInterpreter/CachedInterpreterEmitter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreterEmitter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreterEmitter.cpp index 8422ef9edb..ffd1042594 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreterEmitter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreterEmitter.cpp @@ -19,6 +19,8 @@ void CachedInterpreterEmitter::Write(AnyCallback callback, const void* operands, } std::memcpy(m_code, &callback, sizeof(callback)); m_code += sizeof(callback); + if (size == 0) + return; std::memcpy(m_code, operands, size); m_code += size; }