osx: Use safe string functions for launcher.

The OS X launcher used a few unsafe string functions; use snprintf()
or strlcpy,strlcat here - as this is the launcher for OS X we don't
need to care about portability.
This commit is contained in:
Simon Howard 2014-04-01 21:51:18 -04:00
parent a9d9335b20
commit 5afef298d6
3 changed files with 13 additions and 18 deletions

View file

@ -75,8 +75,7 @@ static void DoExec(const char *executable, const char *iwad, const char *args)
{
char *argv[3];
argv[0] = malloc(strlen(executable_path) + strlen(executable) + 3);
sprintf(argv[0], "%s/%s", executable_path, executable);
asprintf(&argv[0], "%s/%s", executable_path, executable);
if (iwad != NULL || args != NULL)
{

View file

@ -308,15 +308,15 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] =
IWADLocation *iwadList[NUM_IWAD_TYPES];
NSString *location;
unsigned int i;
unsigned int len;
BOOL first;
char *env;
size_t env_len;
[self getIWADList: iwadList];
// Calculate length of environment string.
len = 0;
env_len = 0;
for (i=0; i<NUM_IWAD_TYPES; ++i)
{
@ -324,14 +324,14 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] =
if (location != nil && [location length] > 0)
{
len += [location length] + 1;
env_len += [location length] + 1;
}
}
// Build string.
env = malloc(len);
strcpy(env, "");
env = malloc(env_len);
strlcpy(env, "", env_len);
first = YES;
@ -343,10 +343,10 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] =
{
if (!first)
{
strcat(env, ":");
strlcat(env, ":", env_len);
}
strcat(env, [location UTF8String]);
strlcat(env, [location UTF8String], env_len);
first = NO;
}
}
@ -366,9 +366,7 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] =
doomwadpath = [self doomWadPath];
env = malloc(strlen(doomwadpath) + 15);
sprintf(env, "DOOMWADPATH=%s", doomwadpath);
asprintf(&env, "DOOMWADPATH=%s", doomwadpath);
free(doomwadpath);

View file

@ -297,8 +297,7 @@ static NSString *AppendQuotedFilename(NSString *str, NSString *fileName)
}
game_name = [self->iwadController getGameName];
executable_name = malloc(strlen(PROGRAM_PREFIX) + strlen(game_name) + 1);
sprintf(executable_name, "%s%s", PROGRAM_PREFIX, game_name);
asprintf(&executable_name, "%s%s", PROGRAM_PREFIX, game_name);
ExecuteProgram(executable_name, [iwad UTF8String],
[args UTF8String]);
@ -319,8 +318,7 @@ static NSString *AppendQuotedFilename(NSString *str, NSString *fileName)
// to configure, based on the game selected in the dropdown.
game_name = [self->iwadController getGameName];
arg = malloc(strlen(game_name) + 8);
sprintf(arg, "-game %s", game_name);
asprintf(&arg, "-game %s", game_name);
ExecuteProgram(PROGRAM_PREFIX "setup", NULL, arg);
@ -355,14 +353,14 @@ static NSString *AppendQuotedFilename(NSString *str, NSString *fileName)
- (void) openCMDLINE: (id) sender
{
char *game_name;
const char *game_name;
char filename[32];
// We need to open the appropriate doc file for the currently
// selected game.
game_name = [self->iwadController getGameName];
sprintf(filename, "CMDLINE-%s", game_name);
snprintf(filename, sizeof(filename), "CMDLINE-%s", game_name);
OpenDocumentation(filename);
}