diff --git a/data/rd_output.c b/data/rd_output.c index f5d260b..b859b6d 100644 --- a/data/rd_output.c +++ b/data/rd_output.c @@ -8,6 +8,8 @@ #include #include +#include + #include "rd_util.h" #include "rd_output.h" @@ -91,10 +93,7 @@ static void write_u32(FILE *f, unsigned int n) static void write_ch8(FILE *f, const char *s) { char buffer[9]; - - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "%s", s); - + strlcpy(buffer, s, sizeof(buffer)); fwrite(buffer, 8, 1, f); } diff --git a/data/rd_util.c b/data/rd_util.c index 556f9f7..d05c0e7 100644 --- a/data/rd_util.c +++ b/data/rd_util.c @@ -8,6 +8,9 @@ #include #include +#include +#include + #include "rd_util.h" void ATTR((noreturn)) die(const char *error, ...) @@ -65,19 +68,18 @@ size_t read_or_die(void **ptr, const char *file) void *buffer = NULL, *pos = buffer; FILE *f; - f = fopen(file, "rb"); - if (!f) + if (!(f = fopen(file, "rb"))) { int i; - size_t s; - char *path; + char *path = NULL; + size_t file_len = strlen(file); for (i = 0; i < num_search_paths; i++) { - s = strlen(search_paths[i]) + 1 + strlen(file) + 1; - path = xmalloc(s); - snprintf(path, s, "%s/%s", search_paths[i], file); - f = fopen(path, "rb"); + size_t s = strlen(search_paths[i]) + 1 + file_len + 1; + path = xmalloc(s); + fill_pathname_join(path, search_paths[i], file, s); + f = fopen(path, "rb"); free(path); } } diff --git a/libretro/libretro.c b/libretro/libretro.c index dcac407..5c11b67 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -11,6 +11,7 @@ #include #include #include +#include #if _MSC_VER #include @@ -532,7 +533,7 @@ static void update_variables(bool startup) { char *pch; char str[100]; - snprintf(str, sizeof(str), "%s", var.value); + strlcpy(str, var.value, sizeof(str)); pch = strtok(str, "x"); if (pch) @@ -821,7 +822,7 @@ bool retro_load_game(const struct retro_game_info *info) if (!use_external_savedir) { // > Use WAD directory fallback... - snprintf(g_save_dir, sizeof(g_save_dir), "%s", g_wad_dir); + strlcpy(g_save_dir, g_wad_dir, sizeof(g_save_dir)); } } @@ -855,8 +856,7 @@ failed: struct retro_message msg; char msg_local[256]; - snprintf(msg_local, sizeof(msg_local), - "ROM loading failed..."); + strlcpy(msg_local, "ROM loading failed...", sizeof(msg_local)); msg.msg = msg_local; msg.frames = 360; if (environ_cb) diff --git a/src/d_client.c b/src/d_client.c index be18578..08b603e 100644 --- a/src/d_client.c +++ b/src/d_client.c @@ -101,9 +101,10 @@ void D_CheckNetGame(void) dbool D_NetGetWad(const char* name) { #if defined(HAVE_WAIT_H) - size_t psize = sizeof(packet_header_t) + strlen(name) + 500; packet_header_t *packet; - dbool done = FALSE; + size_t name_len = strlen(name); + size_t psize = sizeof(packet_header_t) + name_len + 500; + dbool done = FALSE; if (!server || strchr(name, '/')) return FALSE; // If it contains path info, reject @@ -113,7 +114,7 @@ dbool D_NetGetWad(const char* name) packet_set(packet, PKT_WAD, 0); *(uint8_t*)(packet+1) = consoleplayer; strcpy(1+(uint8_t*)(packet+1), name); - I_SendPacket(packet, sizeof(packet_header_t) + strlen(name) + 2); + I_SendPacket(packet, sizeof(packet_header_t) + name_len + 2); I_uSleep(10000); } while (!I_GetPacket(packet, psize) || (packet->type != PKT_WAD)); @@ -122,7 +123,7 @@ dbool D_NetGetWad(const char* name) if (!strcasecmp((void*)(packet+1), name)) { pid_t pid; int rv; - uint8_t *p = (uint8_t*)(packet+1) + strlen(name) + 1; + uint8_t *p = (uint8_t*)(packet+1) + name_len + 1; /* Automatic wad file retrieval using wget (supports http and ftp, using URLs) * Unix systems have all these commands handy, this kind of thing is easy