Reduce dependence on strcpy_literal (just a macro for strcpy) - prefer

going through safer strlcpy
This commit is contained in:
libretroadmin 2023-01-22 17:13:38 +01:00
parent 378e90e745
commit 9fbd62d7b8
6 changed files with 42 additions and 48 deletions

View File

@ -218,7 +218,8 @@ static void frontend_gx_get_env(int *argc, char *argv[],
if ( string_starts_with_size(argv[0], "usb1", STRLEN_CONST("usb1")) ||
string_starts_with_size(argv[0], "usb2", STRLEN_CONST("usb2")))
{
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_CORE], "usb");
strlcpy(g_defaults.dirs[DEFAULT_DIR_CORE], "usb",
sizeof(g_defaults.dirs[DEFAULT_DIR_CORE]));
strlcat(g_defaults.dirs[DEFAULT_DIR_CORE], argv[0] + 4,
sizeof(g_defaults.dirs[DEFAULT_DIR_CORE]));
}

View File

@ -1731,7 +1731,7 @@ static void frontend_unix_get_env(int *argc,
{
g_defaults.overlay_set = true;
g_defaults.overlay_enable = false;
strcpy_literal(g_defaults.settings_menu, "ozone");
strlcpy(g_defaults.settings_menu, "ozone", sizeof(g_defaults.settings_menu));
}
#else
char base_path[PATH_MAX] = {0};

View File

@ -346,7 +346,7 @@ static void frontend_uwp_env_get(int *argc, char *argv[],
#ifdef HAVE_MENU
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) || defined(HAVE_OPENGL_CORE)
if (string_is_equal(uwp_device_family, "Windows.Mobile"))
strcpy_literal(g_defaults.settings_menu, "glui");
strlcpy(g_defaults.settings_menu, "glui", sizeof(g_defaults.settings_menu));
#endif
#endif

View File

@ -99,7 +99,7 @@ static void frontend_xdk_get_environment_settings(int *argc, char *argv[],
#endif
#if defined(_XBOX1)
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_CORE], "D:");
strlcpy(g_defaults.dirs[DEFAULT_DIR_CORE], "D:", g_defaults.dirs[DEFAULT_DIR_CORE]);
fill_pathname_join(g_defaults.path_config, g_defaults.dirs[DEFAULT_DIR_CORE],
FILE_PATH_MAIN_CONFIG, sizeof(g_defaults.path_config));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SAVESTATE],
@ -141,22 +141,22 @@ static void frontend_xdk_get_environment_settings(int *argc, char *argv[],
g_defaults.dirs[DEFAULT_DIR_CORE],
"logs", sizeof(g_defaults.dirs[DEFAULT_DIR_LOGS]));
#elif defined(_XBOX360)
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_CORE],
"game:");
strcpy_literal(g_defaults.path_config,
"game:\\retroarch.cfg");
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT],
"game:");
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_SAVESTATE],
"game:\\savestates");
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_PLAYLIST],
"game:\\playlists");
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_SRAM],
"game:\\savefiles");
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_SYSTEM],
"game:\\system");
strcpy_literal(g_defaults.dirs[DEFAULT_DIR_LOGS],
"game:\\logs");
strlcpy(g_defaults.dirs[DEFAULT_DIR_CORE],
"game:", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE]));
strlcpy(g_defaults.path_config,
"game:\\retroarch.cfg", sizeof(g_defaults.path_config));
strlcpy(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT],
"game:", sizeof(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT]));
strlcpy(g_defaults.dirs[DEFAULT_DIR_SAVESTATE],
"game:\\savestates", sizeof(g_defaults.dirs[DEFAULT_DIR_SAVESTATE]));
strlcpy(g_defaults.dirs[DEFAULT_DIR_PLAYLIST],
"game:\\playlists", sizeof(g_defaults.dirs[DEFAULT_DIR_PLAYLIST]));
strlcpy(g_defaults.dirs[DEFAULT_DIR_SRAM],
"game:\\savefiles", sizeof(g_defaults.dirs[DEFAULT_DIR_SRAM]));
strlcpy(g_defaults.dirs[DEFAULT_DIR_SYSTEM],
"game:\\system", sizeof(g_defaults.dirs[DEFAULT_DIR_SYSTEM]));
strlcpy(g_defaults.dirs[DEFAULT_DIR_LOGS],
"game:\\logs", sizeof(g_defaults.dirs[DEFAULT_DIR_LOGS]));
#endif
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO],
g_defaults.dirs[DEFAULT_DIR_CORE],

View File

@ -55,12 +55,13 @@ bool net_ifinfo_new(net_ifinfo_t *list)
PIP_ADAPTER_ADDRESSES addr;
struct net_ifinfo_entry *entry;
size_t interfaces = 0;
ULONG flags = GAA_FLAG_SKIP_ANYCAST |
GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER;
ULONG flags = GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
| GAA_FLAG_SKIP_DNS_SERVER;
ULONG len = 15 * 1024;
PIP_ADAPTER_ADDRESSES addresses = (PIP_ADAPTER_ADDRESSES)calloc(1, len);
list->entries = NULL;
list->entries = NULL;
if (!addresses)
goto failure;
@ -104,15 +105,14 @@ bool net_ifinfo_new(net_ifinfo_t *list)
if (!interfaces)
goto failure;
list->entries =
(struct net_ifinfo_entry*)calloc(interfaces, sizeof(*list->entries));
if (!list->entries)
if (!(list->entries =
(struct net_ifinfo_entry*)calloc(interfaces, sizeof(*list->entries))))
goto failure;
list->size = 0;
list->size = 0;
/* Now create the entries. */
addr = addresses;
entry = list->entries;
addr = addresses;
entry = list->entries;
do
{
@ -161,22 +161,19 @@ failure:
return false;
#elif defined(VITA)
SceNetCtlInfo info;
list->entries = (struct net_ifinfo_entry*)calloc(2, sizeof(*list->entries));
if (!list->entries)
if (!(list->entries = (struct net_ifinfo_entry*)calloc(2, sizeof(*list->entries))))
{
list->size = 0;
return false;
}
strcpy_literal(list->entries[0].name, "lo");
strcpy_literal(list->entries[0].host, "127.0.0.1");
strlcpy(list->entries[0].name, "lo", sizeof(list->entries[0].name));
strlcpy(list->entries[0].host, "127.0.0.1", sizeof(list->entries[0].host));
list->size = 1;
if (!sceNetCtlInetGetInfo(SCE_NETCTL_INFO_GET_IP_ADDRESS, &info))
{
strcpy_literal(list->entries[1].name, "wlan");
strlcpy(list->entries[1].name, "wlan", sizeof(list->entries[1].name));
strlcpy(list->entries[1].host, info.ip_address,
sizeof(list->entries[1].host));
list->size++;
@ -185,17 +182,14 @@ failure:
return true;
#elif defined(HAVE_LIBNX) || defined(_3DS) || defined(GEKKO)
uint32_t addr = 0;
list->entries = (struct net_ifinfo_entry*)calloc(2, sizeof(*list->entries));
if (!list->entries)
if (!(list->entries = (struct net_ifinfo_entry*)calloc(2, sizeof(*list->entries))))
{
list->size = 0;
return false;
}
strcpy_literal(list->entries[0].name, "lo");
strcpy_literal(list->entries[0].host, "127.0.0.1");
strlcpy(list->entries[0].name, "lo", sizeof(list->entries[0].name));
strlcpy(list->entries[0].host, "127.0.0.1", sizeof(list->entries[0].host));
list->size = 1;
#if defined(HAVE_LIBNX)
@ -213,8 +207,7 @@ failure:
if (addr)
{
uint8_t *addr8 = (uint8_t*)&addr;
strcpy_literal(list->entries[1].name,
strlcpy(list->entries[1].name,
#if defined(HAVE_LIBNX)
"switch"
#elif defined(_3DS)
@ -222,7 +215,7 @@ failure:
#else
"gekko"
#endif
);
, sizeof(list->entries[1].name));
snprintf(list->entries[1].host, sizeof(list->entries[1].host),
"%d.%d.%d.%d",
(int)addr8[0], (int)addr8[1], (int)addr8[2], (int)addr8[3]);
@ -236,13 +229,13 @@ failure:
size_t interfaces = 0;
struct ifaddrs *addresses = NULL;
list->entries = NULL;
list->entries = NULL;
if (getifaddrs(&addresses) || !addresses)
goto failure;
/* Count the number of valid interfaces first. */
addr = addresses;
addr = addresses;
do
{

View File

@ -14262,7 +14262,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
strlcat(ext_names, FILE_PATH_CORE_BACKUP_EXTENSION_NO_DOT, sizeof(ext_names));
}
else
strcpy_literal(ext_names, FILE_PATH_CORE_BACKUP_EXTENSION_NO_DOT);
strlcpy(ext_names, FILE_PATH_CORE_BACKUP_EXTENSION_NO_DOT, sizeof(ext_names));
info->exts = strdup(ext_names);
}