From 808e1c9f6f81f93bc0331f3b8fda3b57778fb6bb Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 18 Mar 2012 01:53:03 +0100 Subject: [PATCH] q3map2: fix dangling pointer dereference `last` was used but not initialized. Also fixes a segmentation fault if PATH is not in the environment. --- tools/quake3/q3map2/path_init.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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 ) -- 2.39.2