]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
q3map2: fix crash if command-line argument is missing
authorZack Middleton <zack@cloemail.com>
Wed, 24 Jul 2019 06:11:58 +0000 (01:11 -0500)
committerZack Middleton <zack@cloemail.com>
Fri, 26 Jul 2019 15:18:25 +0000 (10:18 -0500)
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.

tools/quake3/q3map2/main.c
tools/quake3/q3map2/path_init.c

index e4d4250bfa9ff200601785a0107ba13e9f80fdc2..e6b4a5c96e25e8507c4f7f0895eaf32d788fec58 100644 (file)
@@ -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;
                }
index e881fd8501479502abc9813228ccca397ba19906..59d9de3d1cffba6b3f5d86532ffe5003e4a44283 100644 (file)
@@ -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;