From eb3a4033c7d6f1d5e042edd5f416bbc257e40975 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 29 Mar 2014 21:49:57 -0400 Subject: strife: Eliminate use of unsafe string functions. Eliminate use of strcpy, strcat, strncpy, and use the new safe alternatives. --- src/strife/m_menu.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/strife/m_menu.c') diff --git a/src/strife/m_menu.c b/src/strife/m_menu.c index 27a9045c..7f4f18fc 100644 --- a/src/strife/m_menu.c +++ b/src/strife/m_menu.c @@ -54,6 +54,7 @@ #include "m_argv.h" #include "m_controls.h" +#include "m_misc.h" #include "m_saves.h" // [STRIFE] #include "p_saveg.h" @@ -560,7 +561,8 @@ void M_ReadSaveStrings(void) handle = fopen(fname, "rb"); if(handle == NULL) { - strcpy(savegamestrings[i], EMPTYSTRING); + M_StringCopy(savegamestrings[i], EMPTYSTRING, + sizeof(savegamestrings[i])); LoadMenu[i].status = 0; continue; } @@ -765,7 +767,7 @@ void M_SaveSelect(int choice) quickSaveSlot = choice; //saveSlot = choice; - strcpy(saveOldString,savegamestrings[choice]); + M_StringCopy(saveOldString, savegamestrings[choice], sizeof(saveOldString)); if (!strcmp(savegamestrings[choice],EMPTYSTRING)) savegamestrings[choice][0] = 0; saveCharIndex = strlen(savegamestrings[choice]); @@ -1850,7 +1852,8 @@ boolean M_Responder (event_t* ev) case KEY_ESCAPE: saveStringEnter = 0; - strcpy(&savegamestrings[quickSaveSlot][0],saveOldString); + M_StringCopy(savegamestrings[quickSaveSlot], saveOldString, + sizeof(savegamestrings[quickSaveSlot])); break; case KEY_ENTER: @@ -2286,24 +2289,32 @@ void M_Drawer (void) int foundnewline = 0; for (i = 0; i < strlen(messageString + start); i++) + { if (messageString[start + i] == '\n') { - memset(string, 0, sizeof(string)); - strncpy(string, messageString + start, i); + M_StringCopy(string, messageString + start, + sizeof(string)); + if (i < sizeof(string)) + { + string[i] = '\0'; + } + foundnewline = 1; start += i + 1; break; } + } - if (!foundnewline) - { - strcpy(string, messageString + start); - start += strlen(string); - } + if (!foundnewline) + { + M_StringCopy(string, messageString + start, + sizeof(string)); + start += strlen(string); + } - x = 160 - M_StringWidth(string) / 2; - M_WriteText(x, y, string); - y += SHORT(hu_font[0]->height); + x = 160 - M_StringWidth(string) / 2; + M_WriteText(x, y, string); + y += SHORT(hu_font[0]->height); } return; -- cgit v1.2.3