Skip to content

Commit

Permalink
[Project64] Make sure Recompiler_Log_Message can not buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Jan 20, 2018
1 parent f036c78 commit 2c802bd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.cpp
Expand Up @@ -23,12 +23,19 @@ void Recompiler_Log_Message(const char * strFormat, ...)
{
va_list args;
va_start(args, strFormat);
size_t nlen = _vscprintf(strFormat, args) + 3;
char * buffer = (char *)alloca(nlen * sizeof(char));
size_t nlen = _vscprintf(strFormat, args);
char * buffer = (char *)alloca((nlen + 3) * sizeof(char));
if (buffer != NULL)
{
buffer[nlen - 1] = 0;
vsprintf(buffer, strFormat, args);
if (nlen > 0)
{
vsnprintf(buffer, nlen, strFormat, args);
buffer[nlen - 1] = '\0';
}
else
{
buffer[0] = '\0';
}
strcat(buffer, "\r\n");
g_CPULogFile->Log(buffer);
}
Expand Down

0 comments on commit 2c802bd

Please sign in to comment.