From e892c4e4466b2964b5fdf6707452f0ed7614f818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 14 Apr 2026 12:55:29 -0600 Subject: [PATCH] Implement the length check. --- Core/HLE/sceKernelInterrupt.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 1a0c61d91e..09489809e1 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -861,7 +861,14 @@ static int sysclib_sprintf_impl(u32 dst, int limit, u32 fmt, int paramOffset) { } } - VERBOSE_LOG(Log::sceKernel, "sysclib_sprintf result string has length %d, content:", (int)result.length()); + const size_t retval = result.size(); + + // Implement the snprintf length check. + if (limit != 0 && result.length() >= limit) { + result.resize(limit - 1); + } + + VERBOSE_LOG(Log::sceKernel, "sysclib_sprintf result string has length %d (retval: %d), content:", (int)result.length(), (int)retval); VERBOSE_LOG(Log::sceKernel, "%s", result.c_str()); // Since this is a sprintf function and not an actual printf, we don't log to the Sprintf log. // INFO_LOG(Log::Printf, "%s", result.c_str()); @@ -870,7 +877,7 @@ static int sysclib_sprintf_impl(u32 dst, int limit, u32 fmt, int paramOffset) { return 0; } memcpy((char *)Memory::GetPointerUnchecked(dst), result.c_str(), (int)result.length() + 1); - return (int)result.length(); + return (int)retval; } static int sysclib_sprintf(u32 dst, u32 fmt) {