# HG changeset patch # User rubidium # Date 2009-04-10 20:37:05 # Node ID baf78c8eb5f4c9f36f091eaade86e95c089ee7c7 # Parent 0bf7b08b72010aa540cc4e14b9e99a8c616de9f4 (svn r16024) -Codechange: harden string copying on places where it's possible diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp --- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -52,7 +52,7 @@ AIScanner::AIScanner() : /* Create the dummy AI */ this->engine->ResetCrashed(); - strcpy(this->main_script, "%_dummy"); + strecpy(this->main_script, "%_dummy", lastof(this->main_script)); extern void AI_CreateAIInfoDummy(HSQUIRRELVM vm); AI_CreateAIInfoDummy(this->engine->GetVM()); } diff --git a/src/fileio.cpp b/src/fileio.cpp --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -363,7 +363,7 @@ FILE *FioFOpenFile(const char *filename, char resolved_name[MAX_RESOLVED_LENGTH]; /* Filenames in tars are always forced to be lowercase */ - strcpy(resolved_name, filename); + strecpy(resolved_name, filename, lastof(resolved_name)); strtolower(resolved_name); size_t resolved_len = strlen(resolved_name); @@ -376,9 +376,9 @@ FILE *FioFOpenFile(const char *filename, /* Apply link */ char resolved_name2[MAX_RESOLVED_LENGTH]; const std::string &dest = link->second; - strcpy(resolved_name2, &(resolved_name[len])); - strcpy(resolved_name, dest.c_str()); - strcpy(&(resolved_name[dest.length()]), resolved_name2); + strecpy(resolved_name2, &(resolved_name[len]), lastof(resolved_name2)); + strecpy(resolved_name, dest.c_str(), lastof(resolved_name)); + strecpy(&(resolved_name[dest.length()]), resolved_name2, lastof(resolved_name)); break; // Only resolve one level } } @@ -640,7 +640,7 @@ bool TarListAddFile(const char *filename /* Process relative path. * Note: The destination of links must not contain any directory-links. */ - strcpy(dest, name); + strecpy(dest, name, lastof(dest)); char *destpos = strrchr(dest, PATHSEPCHAR); if (destpos == NULL) destpos = dest; *destpos = '\0'; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1508,7 +1508,7 @@ public: this->vscroll.cap--; case SLD_SAVE_GAME: this->GenerateFileName(); break; - case SLD_SAVE_SCENARIO: strcpy(this->edit_str_buf, "UNNAMED"); break; + case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break; default: break; } diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp --- a/src/music/win32_m.cpp +++ b/src/music/win32_m.cpp @@ -23,7 +23,7 @@ static FMusicDriver_Win32 iFMusicDriver_ void MusicDriver_Win32::PlaySong(const char *filename) { assert(filename != NULL); - strcpy(_midi.start_song, filename); + strecpy(_midi.start_song, filename, lastof(_midi.start_song)); _midi.playing = true; _midi.stop_song = false; SetEvent(_midi.wait_obj); diff --git a/src/screenshot.cpp b/src/screenshot.cpp --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -456,7 +456,7 @@ const char *GetScreenshotFormatDesc(int void SetScreenshotFormat(int i) { _cur_screenshot_format = i; - strcpy(_screenshot_format_name, _screenshot_formats[i].extension); + strecpy(_screenshot_format_name, _screenshot_formats[i].extension, lastof(_screenshot_format_name)); } /* screenshot generator that dumps the current video buffer */ diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -554,7 +554,7 @@ static void ini_save_settings(IniFile *i uint32 i = (uint32)ReadValue(ptr, sld->conv); switch (sdb->cmd) { - case SDT_BOOLX: strcpy(buf, (i != 0) ? "true" : "false"); break; + case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break; case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break; case SDT_ONEOFMANY: make_oneofmany(buf, lastof(buf), sdb->many, i); break; case SDT_MANYOFMANY: make_manyofmany(buf, lastof(buf), sdb->many, i); break; @@ -564,9 +564,9 @@ static void ini_save_settings(IniFile *i case SDT_STRING: switch (GetVarMemType(sld->conv)) { - case SLE_VAR_STRB: strcpy(buf, (char*)ptr); break; + case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break; case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break; - case SLE_VAR_STR: strcpy(buf, *(char**)ptr); break; + case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break; case SLE_VAR_STRQ: if (*(char**)ptr == NULL) { buf[0] = '\0'; diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -1193,9 +1193,9 @@ static void WriteLangfile(const char *fi hdr.text_dir = _lang_textdir; hdr.winlangid = TO_LE16(_lang_winlangid); hdr.newgrflangid = _lang_newgrflangid; - strcpy(hdr.name, _lang_name); - strcpy(hdr.own_name, _lang_ownname); - strcpy(hdr.isocode, _lang_isocode); + strecpy(hdr.name, _lang_name, lastof(hdr.name)); + strecpy(hdr.own_name, _lang_ownname, lastof(hdr.own_name)); + strecpy(hdr.isocode, _lang_isocode, lastof(hdr.isocode)); fwrite(&hdr, sizeof(hdr), 1, f); diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -222,7 +222,7 @@ static void DedicatedHandleKeyInput() #else /* Handle console input, and singal console thread, it can accept input again */ assert_compile(lengthof(_win_console_thread_buffer) <= lengthof(input_line)); - strcpy(input_line, _win_console_thread_buffer); + strecpy(input_line, _win_console_thread_buffer, lastof(input_line)); SetEvent(_hWaitForInputHandling); #endif