From: Ben Noordhuis Date: Sun, 18 Mar 2012 00:53:03 +0000 (+0100) Subject: q3map2: fix dangling pointer dereference X-Git-Tag: xonotic-v0.7.0~16^2~6^2~2^2^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=808e1c9f6f81f93bc0331f3b8fda3b57778fb6bb;p=xonotic%2Fnetradiant.git q3map2: fix dangling pointer dereference `last` was used but not initialized. Also fixes a segmentation fault if PATH is not in the environment. --- diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index ac8fa328..5a31644a 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -111,20 +111,16 @@ void LokiInitPaths( char *argv0 ){ home = "."; } + path = getenv( "PATH" ); + /* 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; + last = path; /* go through each : segment of path */ while ( last[ 0 ] != '\0' && found == qfalse )