Browse Source

engine: disallow zero-width strings for getenv()

pull/2/head
Alibek Omarov 5 years ago
parent
commit
82c54b1b54
  1. 6
      engine/common/filesystem.c
  2. 8
      engine/common/host.c
  3. 4
      engine/common/identification.c
  4. 2
      engine/common/launcher.c
  5. 2
      engine/platform/posix/sys_posix.c

6
engine/common/filesystem.c

@ -1383,9 +1383,11 @@ void FS_Rescan( void ) @@ -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

8
engine/common/host.c

@ -899,7 +899,9 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha @@ -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 @@ -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 ));
}

4
engine/common/identification.c

@ -640,7 +640,7 @@ void ID_Init( void ) @@ -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 ) @@ -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 )

2
engine/common/launcher.c

@ -68,7 +68,7 @@ int main( int argc, char** argv ) @@ -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";
}

2
engine/platform/posix/sys_posix.c

@ -33,7 +33,7 @@ static qboolean Sys_FindExecutable( const char *baseName, char *buf, size_t size @@ -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 );

Loading…
Cancel
Save