From b23eaba217ebe161569a6702e47d8c3103311dbc Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sun, 22 Jan 2023 18:57:17 +0100 Subject: [PATCH] Try to use strlcpy/strlcat instead of snprintf when possible --- gfx/drivers/d3d9cg.c | 46 +++++++++++++++++++------------ network/drivers_wifi/connmanctl.c | 35 +++++++++++------------ 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/gfx/drivers/d3d9cg.c b/gfx/drivers/d3d9cg.c index 2c525731a4..5e50ecf145 100644 --- a/gfx/drivers/d3d9cg.c +++ b/gfx/drivers/d3d9cg.c @@ -507,10 +507,10 @@ static void d3d9_cg_renderchain_bind_prev(d3d9_renderchain_t *chain, { unsigned i; float texture_size[2]; - char attr_texture[64] = {0}; - char attr_input_size[64] = {0}; - char attr_tex_size[64] = {0}; - char attr_coord[64] = {0}; + char attr_texture[64]; + char attr_input_size[64]; + char attr_tex_size[64]; + char attr_coord[64]; static const char *prev_names[] = { "PREV", "PREV1", @@ -526,15 +526,21 @@ static void d3d9_cg_renderchain_bind_prev(d3d9_renderchain_t *chain, for (i = 0; i < TEXTURES - 1; i++) { + char prev_name[32]; CGparameter param; float video_size[2]; CGprogram fprg = (CGprogram)pass->fprg; CGprogram vprg = (CGprogram)pass->vprg; - snprintf(attr_texture, sizeof(attr_texture), "%s.texture", prev_names[i]); - snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", prev_names[i]); - snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", prev_names[i]); - snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", prev_names[i]); + strlcpy(prev_name, prev_names[i], sizeof(prev_name)); + strlcpy(attr_texture, prev_name, sizeof(attr_texture)); + strlcat(attr_texture, ".texture", sizeof(attr_texture)); + strlcpy(attr_input_size, prev_name, sizeof(attr_input_size)); + strlcat(attr_input_size, ".video_size", sizeof(attr_input_size)); + strlcpy(attr_tex_size, prev_name, sizeof(attr_tex_size)); + strlcat(attr_tex_size, ".texture_size", sizeof(attr_tex_size)); + strlcpy(attr_coord, prev_name, sizeof(attr_coord)); + strlcat(attr_coord, ".tex_coord", sizeof(attr_coord)); video_size[0] = chain->prev.last_width[ (chain->prev.ptr - (i + 1)) & TEXTURESMASK]; @@ -606,18 +612,22 @@ static void d3d9_cg_renderchain_bind_pass( CGparameter param; float video_size[2]; float texture_size[2]; - char pass_base[64] = {0}; - char attr_texture[64] = {0}; - char attr_input_size[64] = {0}; - char attr_tex_size[64] = {0}; - char attr_coord[64] = {0}; + char pass_base[64]; + char attr_texture[64]; + char attr_input_size[64]; + char attr_tex_size[64]; + char attr_coord[64]; struct shader_pass *curr_pass = (struct shader_pass*)&chain->passes->data[i]; - snprintf(pass_base, sizeof(pass_base), "PASS%u", i); - snprintf(attr_texture, sizeof(attr_texture), "%s.texture", pass_base); - snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", pass_base); - snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", pass_base); - snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", pass_base); + snprintf(pass_base, sizeof(pass_base), "PASS%u", i); + strlcpy(attr_texture, pass_base, sizeof(attr_texture)); + strlcat(attr_texture, ".texture", sizeof(attr_texture)); + strlcpy(attr_input_size, pass_base, sizeof(attr_input_size)); + strlcat(attr_input_size, ".video_size", sizeof(attr_input_size)); + strlcpy(attr_tex_size, pass_base, sizeof(attr_tex_size)); + strlcat(attr_tex_size, ".texture_size", sizeof(attr_tex_size)); + strlcpy(attr_coord, pass_base, sizeof(attr_coord)); + strlcat(attr_coord, ".tex_coord", sizeof(attr_coord)); video_size[0] = curr_pass->last_width; video_size[1] = curr_pass->last_height; diff --git a/network/drivers_wifi/connmanctl.c b/network/drivers_wifi/connmanctl.c index f3b008f86e..95ba029e6c 100644 --- a/network/drivers_wifi/connmanctl.c +++ b/network/drivers_wifi/connmanctl.c @@ -181,7 +181,7 @@ static bool connmanctl_tether_status(connman_t *connman) } static void connmanctl_tether_toggle( - connman_t *connman, bool switch_on, char* apname, char* passkey) + connman_t *connman, bool switch_on, char* ap_name, char *pass_key) { /* Starts / stops the tethering service on wi-fi device */ char output[256] = {0}; @@ -193,7 +193,7 @@ static void connmanctl_tether_toggle( snprintf(connman->command, sizeof(connman->command), "\ connmanctl tether wifi %s %s %s", - switch_on ? "on" : "off", apname, passkey); + switch_on ? "on" : "off", ap_name, pass_key); command_file = popen(connman->command, "r"); @@ -386,9 +386,8 @@ static bool connmanctl_connect_ssid( connmanctl_tether_toggle(connman, false, "", ""); } - snprintf(connman->command, sizeof(connman->command), - "connmanctl connect %s", - netinfo->netid); + strlcpy(connman->command, "connmanctl connect ", sizeof(connman->command)); + strlcat(connman->command, netinfo->netid, sizeof(connman->command)); pclose(popen(connman->command, "r")); @@ -565,9 +564,9 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil * tethering service is already running / not running * before performing the desired action */ + char ap_name[64]; + char pass_key[256]; FILE *command_file = NULL; - char apname[64] = {0}; - char passkey[256] = {0}; char ln[512] = {0}; char ssid[64] = {0}; char service[256] = {0}; @@ -612,10 +611,10 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil RARCH_LOG("[CONNMANCTL] Tether start stop: creating new config \"%s\"\n", configfile); - snprintf(apname, sizeof(apname), "LakkaAccessPoint"); - snprintf(passkey, sizeof(passkey), "RetroArch"); + strlcpy(ap_name, "LakkaAccessPoint", sizeof(ap_name)); + strlcpy(pass_key, "RetroArch", sizeof(pass_key)); - fprintf(command_file, "APNAME=%s\nPASSWORD=%s", apname, passkey); + fprintf(command_file, "APNAME=%s\nPASSWORD=%s", ap_name, pass_key); fclose(command_file); @@ -653,21 +652,19 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil if (i == 1) { - strlcpy(apname, ln, sizeof(apname)); + strlcpy(ap_name, ln, sizeof(ap_name)); RARCH_LOG("[CONNMANCTL] Tether start stop: found APNAME: \"%s\"\n", - apname); + ap_name); continue; } if (i == 2) { - strlcpy(passkey, ln, sizeof(passkey)); - + strlcpy(pass_key, ln, sizeof(pass_key)); RARCH_LOG("[CONNMANCTL] Tether start stop: found PASSWORD: \"%s\"\n", - passkey); - + pass_key); continue; } @@ -682,7 +679,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil pclose(command_file); } - if (!apname || !passkey) + if (!ap_name || !pass_key) { RARCH_ERR("[CONNMANCTL] Tether start stop: APNAME or PASSWORD missing\n"); @@ -753,7 +750,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil snprintf(connman->command, sizeof(connman->command), msg_hash_to_str(MSG_LOCALAP_STARTING), - apname, passkey); + ap_name, pass_key); runloop_msg_queue_push(connman->command, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, @@ -782,7 +779,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil RARCH_LOG("[CONNMANCTL] Tether start stop: calling tether_toggle()\n"); /* call the tether toggle function */ - connmanctl_tether_toggle(connman, start, apname, passkey); + connmanctl_tether_toggle(connman, start, ap_name, pass_key); RARCH_LOG("[CONNMANCTL] Tether start stop: end\n"); }