From: Zack Middleton Date: Wed, 24 Jul 2019 06:11:58 +0000 (-0500) Subject: q3map2: fix crash if command-line argument is missing X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7f034b8ced2966f3601f2f96f3c58ae64a062ece;p=xonotic%2Fnetradiant.git q3map2: fix crash if command-line argument is missing Running `q3map2 -fs_forbiddenpath -v mapname.map` would crash because -v gets replaced with NULL in main(). Running `q3map2 -threads` would crash because missing next argument for number of threads. --- diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index e4d4250b..e6b4a5c9 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -122,14 +122,16 @@ int main( int argc, char **argv ){ /* -help */ if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" ) || !strcmp( argv[ i ], "-help" ) ) { - HelpMain(argv[i+1]); + HelpMain( ( i + 1 < argc ) ? argv[ i + 1 ] : NULL ); return 0; } /* -connect */ if ( !strcmp( argv[ i ], "-connect" ) ) { - argv[ i ] = NULL; - i++; + if ( ++i >= argc || !argv[ i ] ) { + Error( "Out of arguments: No address specified after %s", argv[ i - 1 ] ); + } + argv[ i - 1 ] = NULL; Broadcast_Setup( argv[ i ] ); argv[ i ] = NULL; } @@ -156,8 +158,10 @@ int main( int argc, char **argv ){ /* patch subdivisions */ else if ( !strcmp( argv[ i ], "-subdivisions" ) ) { - argv[ i ] = NULL; - i++; + if ( ++i >= argc || !argv[ i ] ) { + Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] ); + } + argv[ i - 1 ] = NULL; patchSubdivisions = atoi( argv[ i ] ); argv[ i ] = NULL; if ( patchSubdivisions <= 0 ) { @@ -167,8 +171,10 @@ int main( int argc, char **argv ){ /* threads */ else if ( !strcmp( argv[ i ], "-threads" ) ) { - argv[ i ] = NULL; - i++; + if ( ++i >= argc || !argv[ i ] ) { + Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] ); + } + argv[ i - 1 ] = NULL; numthreads = atoi( argv[ i ] ); argv[ i ] = NULL; } diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index e881fd85..59d9de3d 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -470,7 +470,7 @@ void InitPaths( int *argc, char **argv ){ /* -game */ if ( strcmp( argv[ i ], "-game" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -483,7 +483,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_forbiddenpath */ else if ( strcmp( argv[ i ], "-fs_forbiddenpath" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -511,7 +511,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_basepath */ else if ( strcmp( argv[ i ], "-fs_basepath" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -521,7 +521,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_game */ else if ( strcmp( argv[ i ], "-fs_game" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -531,7 +531,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_home */ else if ( strcmp( argv[ i ], "-fs_home" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -548,7 +548,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_homebase */ else if ( strcmp( argv[ i ], "-fs_homebase" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -558,7 +558,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_homepath - sets both of them */ else if ( strcmp( argv[ i ], "-fs_homepath" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; @@ -569,7 +569,7 @@ void InitPaths( int *argc, char **argv ){ /* -fs_pakpath */ else if ( strcmp( argv[ i ], "-fs_pakpath" ) == 0 ) { - if ( ++i >= *argc ) { + if ( ++i >= *argc || !argv[ i ] ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL;