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")) || if ( string_starts_with_size(argv[0], "usb1", STRLEN_CONST("usb1")) ||
string_starts_with_size(argv[0], "usb2", STRLEN_CONST("usb2"))) 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, strlcat(g_defaults.dirs[DEFAULT_DIR_CORE], argv[0] + 4,
sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); 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_set = true;
g_defaults.overlay_enable = false; g_defaults.overlay_enable = false;
strcpy_literal(g_defaults.settings_menu, "ozone"); strlcpy(g_defaults.settings_menu, "ozone", sizeof(g_defaults.settings_menu));
} }
#else #else
char base_path[PATH_MAX] = {0}; 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 #ifdef HAVE_MENU
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) || defined(HAVE_OPENGL_CORE) #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) || defined(HAVE_OPENGL_CORE)
if (string_is_equal(uwp_device_family, "Windows.Mobile")) 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
#endif #endif

View File

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

View File

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