Skip to content

Commit

Permalink
engine: fix buffer overflow in Sys_PrintLog
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Aug 3, 2024
1 parent fb7f57c commit 4420ffd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions engine/common/sys_con.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ void Sys_PrintLog( const char *pMsg )
const struct tm *crt_tm;
char logtime[32] = "";
static char lastchar;
size_t len;

time( &crt_time );
crt_tm = localtime( &crt_time );
Expand All @@ -307,18 +308,20 @@ void Sys_PrintLog( const char *pMsg )
// spew to stdout
Sys_PrintStdout( logtime, pMsg );

len = Q_strlen( pMsg );

if( !s_ld.logfile )
{
// save last char to detect when line was not ended
lastchar = pMsg[Q_strlen( pMsg ) - 1];
lastchar = len > 0 ? pMsg[len - 1] : 0;
return;
}

if( !lastchar || lastchar == '\n')
strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S] ", crt_tm ); //full time

// save last char to detect when line was not ended
lastchar = pMsg[Q_strlen( pMsg ) - 1];
lastchar = len > 0 ? pMsg[len - 1] : 0;

Sys_PrintLogfile( s_ld.logfileno, logtime, pMsg, false );
Sys_FlushLogfile();
Expand Down

0 comments on commit 4420ffd

Please sign in to comment.