From 82c54b1b546cdd6ed6ae37f139e14b31cf731bb1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 19 Apr 2020 13:02:36 +0300 Subject: [PATCH] engine: disallow zero-width strings for getenv() --- engine/common/filesystem.c | 6 ++++-- engine/common/host.c | 8 +++++--- engine/common/identification.c | 4 ++-- engine/common/launcher.c | 2 +- engine/platform/posix/sys_posix.c | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/engine/common/filesystem.c b/engine/common/filesystem.c index 333f8688..0977aa23 100644 --- a/engine/common/filesystem.c +++ b/engine/common/filesystem.c @@ -1383,9 +1383,11 @@ void FS_Rescan( void ) FS_AddPak_Fullpath( va( "%sextras_%s.pak", SDL_GetBasePath(), GI->gamefolder ), NULL, extrasFlags ); } #else - if( ( str = getenv( "XASH3D_EXTRAS_PAK1" ) ) ) + str = getenv( "XASH3D_EXTRAS_PAK1" ); + if( COM_CheckString( str ) ) FS_AddPak_Fullpath( str, NULL, extrasFlags ); - if( ( str = getenv( "XASH3D_EXTRAS_PAK2" ) ) ) + str = getenv( "XASH3D_EXTRAS_PAK2" ); + if( COM_CheckString( str ) ) FS_AddPak_Fullpath( str, NULL, extrasFlags ); #endif diff --git a/engine/common/host.c b/engine/common/host.c index ac1a18f7..079cc5c0 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -899,7 +899,9 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha Platform_Init(); - if( ( baseDir = getenv( "XASH3D_BASEDIR" ) ) ) + baseDir = getenv( "XASH3D_BASEDIR" ); + + if( COM_CheckString( baseDir ) ) { Q_strncpy( host.rootdir, baseDir, sizeof(host.rootdir) ); } @@ -932,9 +934,9 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha host.rodir[0] = 0; if( !Sys_GetParmFromCmdLine( "-rodir", host.rodir )) { - char *roDir; + char *roDir = getenv( "XASH3D_RODIR" ); - if(( roDir = getenv( "XASH3D_RODIR" ))) + if( COM_CheckString( roDir )) Q_strncpy( host.rodir, roDir, sizeof( host.rodir )); } diff --git a/engine/common/identification.c b/engine/common/identification.c index 833d03bc..432b401a 100644 --- a/engine/common/identification.c +++ b/engine/common/identification.c @@ -640,7 +640,7 @@ void ID_Init( void ) #else { const char *home = getenv( "HOME" ); - if( home ) + if( COM_CheckString( home ) ) { FILE *cfg = fopen( va( "%s/.config/.xash_id", home ), "r" ); if( !cfg ) @@ -690,7 +690,7 @@ void ID_Init( void ) #else { const char *home = getenv( "HOME" ); - if( home ) + if( COM_CheckString( home ) ) { FILE *cfg = fopen( va( "%s/.config/.xash_id", home ), "w" ); if( !cfg ) diff --git a/engine/common/launcher.c b/engine/common/launcher.c index a2d0001c..2100839f 100644 --- a/engine/common/launcher.c +++ b/engine/common/launcher.c @@ -68,7 +68,7 @@ int main( int argc, char** argv ) char gamedir_buf[32] = ""; const char *gamedir = getenv( "XASH3D_GAMEDIR" ); - if( !gamedir ) + if( !COM_CheckString( gamedir ) ) { gamedir = "valve"; } diff --git a/engine/platform/posix/sys_posix.c b/engine/platform/posix/sys_posix.c index 8ae7879c..dd448726 100644 --- a/engine/platform/posix/sys_posix.c +++ b/engine/platform/posix/sys_posix.c @@ -33,7 +33,7 @@ static qboolean Sys_FindExecutable( const char *baseName, char *buf, size_t size return false; envPath = getenv( "PATH" ); - if( !envPath ) + if( !COM_CheckString( envPath ) ) return false; baseNameLength = Q_strlen( baseName );