]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
q3map2: fix dangling pointer dereference
authorBen Noordhuis <info@bnoordhuis.nl>
Sun, 18 Mar 2012 00:53:03 +0000 (01:53 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Sun, 18 Mar 2012 01:17:09 +0000 (02:17 +0100)
`last` was used but not initialized.

Also fixes a segmentation fault if PATH is not in the environment.

tools/quake3/q3map2/path_init.c

index ac8fa328f8501f2369d9302260eeb117264873e6..5a31644a90c3f836bd674202305fc6617946761a 100644 (file)
@@ -111,20 +111,16 @@ void LokiInitPaths( char *argv0 ){
                home = ".";
        }
 
                home = ".";
        }
 
+       path = getenv( "PATH" );
+
        /* do some path divining */
        strcpy( temp, argv0 );
        if ( strrchr( temp, '/' ) ) {
                argv0 = strrchr( argv0, '/' ) + 1;
        }
        /* do some path divining */
        strcpy( temp, argv0 );
        if ( strrchr( temp, '/' ) ) {
                argv0 = strrchr( argv0, '/' ) + 1;
        }
-       else
-       {
-               /* get path environment variable */
-               path = getenv( "PATH" );
-
-               /* minor setup */
-               last[ 0 ] = path[ 0 ];
-               last[ 1 ] = '\0';
+       else if ( path ) {
                found = qfalse;
                found = qfalse;
+               last = path;
 
                /* go through each : segment of path */
                while ( last[ 0 ] != '\0' && found == qfalse )
 
                /* go through each : segment of path */
                while ( last[ 0 ] != '\0' && found == qfalse )