Skip to content

Commit 4420ffd

Browse files
committed
engine: fix buffer overflow in Sys_PrintLog
1 parent fb7f57c commit 4420ffd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

engine/common/sys_con.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ void Sys_PrintLog( const char *pMsg )
297297
const struct tm *crt_tm;
298298
char logtime[32] = "";
299299
static char lastchar;
300+
size_t len;
300301

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

311+
len = Q_strlen( pMsg );
312+
310313
if( !s_ld.logfile )
311314
{
312315
// save last char to detect when line was not ended
313-
lastchar = pMsg[Q_strlen( pMsg ) - 1];
316+
lastchar = len > 0 ? pMsg[len - 1] : 0;
314317
return;
315318
}
316319

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

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

323326
Sys_PrintLogfile( s_ld.logfileno, logtime, pMsg, false );
324327
Sys_FlushLogfile();

0 commit comments

Comments
 (0)