q3map2: harden UNIX path sniffer against buffer overflows

This commit is contained in:
Ben Noordhuis 2012-03-18 02:00:09 +01:00
parent 808e1c9f6f
commit 3a959349ac

View file

@ -114,7 +114,7 @@ void LokiInitPaths( char *argv0 ){
path = getenv( "PATH" ); path = getenv( "PATH" );
/* do some path divining */ /* do some path divining */
strcpy( temp, argv0 ); Q_strncpyz( temp, argv0, sizeof( temp ) );
if ( strrchr( temp, '/' ) ) { if ( strrchr( temp, '/' ) ) {
argv0 = strrchr( argv0, '/' ) + 1; argv0 = strrchr( argv0, '/' ) + 1;
} }
@ -136,17 +136,17 @@ void LokiInitPaths( char *argv0 ){
/* found home dir candidate */ /* found home dir candidate */
if ( *path == '~' ) { if ( *path == '~' ) {
strcpy( temp, home ); Q_strncpyz( temp, home, sizeof( temp ) );
path++; path++;
} }
/* concatenate */ /* concatenate */
if ( last > ( path + 1 ) ) { if ( last > ( path + 1 ) ) {
strncat( temp, path, ( last - path ) ); Q_strncat( temp, sizeof( temp ), path, ( last - path ) );
strcat( temp, "/" ); Q_strcat( temp, sizeof( temp ), "/" );
} }
strcat( temp, "./" ); Q_strcat( temp, sizeof( temp ), "./" );
strcat( temp, argv0 ); Q_strcat( temp, sizeof( temp ), argv0 );
/* verify the path */ /* verify the path */
if ( access( temp, X_OK ) == 0 ) { if ( access( temp, X_OK ) == 0 ) {