From 61643585e0ce0311ef8220b65224072e440e3647 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 29 Jan 2022 03:04:00 +0300 Subject: [PATCH] engine: fix NULL ptr dereference when log file cannot be opened --- engine/common/sys_con.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/engine/common/sys_con.c b/engine/common/sys_con.c index 1f29cb83..6ca3c7b9 100644 --- a/engine/common/sys_con.c +++ b/engine/common/sys_con.c @@ -113,11 +113,16 @@ void Sys_InitLog( void ) if( s_ld.log_active ) { s_ld.logfile = fopen( s_ld.log_path, mode ); - if( !s_ld.logfile ) Con_Reportf( S_ERROR "Sys_InitLog: can't create log file %s\n", s_ld.log_path ); - - fprintf( s_ld.logfile, "=================================================================================\n" ); - fprintf( s_ld.logfile, "\t%s (build %i) started at %s\n", s_ld.title, Q_buildnum(), Q_timestamp( TIME_FULL )); - fprintf( s_ld.logfile, "=================================================================================\n" ); + if( !s_ld.logfile ) + { + Con_Reportf( S_ERROR "Sys_InitLog: can't create log file %s\n", s_ld.log_path ); + } + else + { + fprintf( s_ld.logfile, "=================================================================================\n" ); + fprintf( s_ld.logfile, "\t%s (build %i) started at %s\n", s_ld.title, Q_buildnum(), Q_timestamp( TIME_FULL )); + fprintf( s_ld.logfile, "=================================================================================\n" ); + } } }