From 112d02eaf58ef10c549f76eded3894a3679aafe9 Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Tue, 6 Aug 2024 16:29:53 -0400 Subject: [PATCH] Debugger: Track remaining buffer size for snprintf to prevent fortify fail --- pcsx2/DebugTools/DisassemblyManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pcsx2/DebugTools/DisassemblyManager.cpp b/pcsx2/DebugTools/DisassemblyManager.cpp index deee8509a4..af02c1ef26 100644 --- a/pcsx2/DebugTools/DisassemblyManager.cpp +++ b/pcsx2/DebugTools/DisassemblyManager.cpp @@ -53,6 +53,7 @@ static void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char* return; } + char* arguments_start = arguments; const char* jumpAddress = strstr(disasm,"->$"); const char* jumpRegister = strstr(disasm,"->"); while (*disasm != 0) @@ -66,9 +67,9 @@ static void parseDisasm(SymbolMap& map, const char* disasm, char* opcode, char* const std::string addressSymbol = map.GetLabelName(branchTarget); if (!addressSymbol.empty() && insertSymbols) { - arguments += std::snprintf(arguments, arguments_size, "%s",addressSymbol.c_str()); + arguments += std::snprintf(arguments, arguments_size - (arguments - arguments_start), "%s",addressSymbol.c_str()); } else { - arguments += std::snprintf(arguments, arguments_size, "0x%08X",branchTarget); + arguments += std::snprintf(arguments, arguments_size - (arguments - arguments_start), "0x%08X",branchTarget); } disasm += 3+2+8;