Prefer to use strlcpy/strlcat instead of strcpy/strcat

This commit is contained in:
twinaphex 2020-01-30 22:14:50 +01:00
parent 3fc8aa7071
commit 941b5f83f3
2 changed files with 19 additions and 18 deletions

View File

@ -60,32 +60,33 @@
static enum frontend_fork ctr_fork_mode = FRONTEND_FORK_NONE;
static const char* elf_path_cst = "sdmc:/retroarch/retroarch.3dsx";
static void get_first_valid_core(char* path_return)
#ifdef IS_SALAMANDER
static void get_first_valid_core(char* path_return, size_t len)
{
DIR* dir;
struct dirent* ent;
const char* extension = envIsHomebrew() ? ".3dsx" : ".cia";
DIR *dir = opendir("sdmc:/retroarch/cores");
path_return[0] = '\0';
path_return[0] = '\0';
dir = opendir("sdmc:/retroarch/cores");
if (dir != NULL)
if (dir)
{
while (ent = readdir(dir))
{
if (ent == NULL)
if (!ent)
break;
if (strlen(ent->d_name) > strlen(extension) && !strcmp(ent->d_name + strlen(ent->d_name) - strlen(extension), extension))
if (strlen(ent->d_name) > strlen(extension)
&& !strcmp(ent->d_name + strlen(ent->d_name) - strlen(extension), extension))
{
strcpy(path_return, "sdmc:/retroarch/cores");
strcat(path_return, "/");
strcat(path_return, ent->d_name);
strlcpy(path_return, "sdmc:/retroarch/cores/", len);
strlcat(path_return, ent->d_name, len);
break;
}
}
closedir(dir);
}
}
#endif
static void frontend_ctr_get_environment_settings(int* argc, char* argv[],
void* args, void* params_data)
@ -212,7 +213,7 @@ static void frontend_ctr_exec(const char* path, bool should_load_game)
#ifndef IS_SALAMANDER
if (should_load_game && !path_is_empty(RARCH_PATH_CONTENT))
{
strcpy(game_path, path_get(RARCH_PATH_CONTENT));
strlcpy(game_path, path_get(RARCH_PATH_CONTENT), sizeof(game_path));
arg_data[args] = game_path;
arg_data[args + 1] = NULL;
args++;
@ -233,7 +234,7 @@ static void frontend_ctr_exec(const char* path, bool should_load_game)
core_path[0] = '\0';
/* find first valid core and load it if the target core doesnt exist */
get_first_valid_core(&core_path[0]);
get_first_valid_core(&core_path[0], sizeof(core_path));
if (core_path[0] == '\0')
{

View File

@ -145,7 +145,7 @@ static void on_applet_hook(AppletHookType hook, void *param)
#endif /* HAVE_LIBNX */
#ifdef IS_SALAMANDER
static void get_first_valid_core(char *path_return)
static void get_first_valid_core(char *path_return, size_t len)
{
DIR *dir;
struct dirent *ent;
@ -162,9 +162,9 @@ static void get_first_valid_core(char *path_return)
break;
if (strlen(ent->d_name) > strlen(extension) && !strcmp(ent->d_name + strlen(ent->d_name) - strlen(extension), extension))
{
strcpy(path_return, SD_PREFIX "/retroarch/cores");
strcat(path_return, "/");
strcat(path_return, ent->d_name);
strlcpy(path_return, SD_PREFIX "/retroarch/cores", len);
strlcat(path_return, "/", len);
strlcat(path_return, ent->d_name, len);
break;
}
}
@ -332,7 +332,7 @@ static void frontend_switch_exec(const char *path, bool should_load_game)
#ifndef IS_SALAMANDER
if (should_load_game && !path_is_empty(RARCH_PATH_CONTENT))
{
strcpy(game_path, path_get(RARCH_PATH_CONTENT));
strlcpy(game_path, path_get(RARCH_PATH_CONTENT), sizeof(game_path));
arg_data[args] = game_path;
arg_data[args + 1] = NULL;
args++;
@ -351,7 +351,7 @@ static void frontend_switch_exec(const char *path, bool should_load_game)
char core_path[PATH_MAX];
/* find first valid core and load it if the target core doesnt exist */
get_first_valid_core(&core_path[0]);
get_first_valid_core(&core_path[0], PATH_MAX);
if (core_path[0] == '\0')
svcExitProcess();