diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index 55dcdcd65f..a9ea467a9b 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -387,7 +387,7 @@ void DebugInit(int flags) pEnd--; } - strcpy(theLogFileNamePrev, dirbuf); + strlcpy(theLogFileNamePrev, dirbuf, ARRAY_SIZE(theLogFileNamePrev)); strlcat(theLogFileNamePrev, gAppPrefix, ARRAY_SIZE(theLogFileNamePrev)); strlcat(theLogFileNamePrev, DEBUG_FILE_NAME_PREV, ARRAY_SIZE(theLogFileNamePrev)); if (rts::ClientInstance::getInstanceId() > 1u) @@ -397,7 +397,7 @@ void DebugInit(int flags) } strlcat(theLogFileNamePrev, ".txt", ARRAY_SIZE(theLogFileNamePrev)); - strcpy(theLogFileName, dirbuf); + strlcpy(theLogFileName, dirbuf, ARRAY_SIZE(theLogFileNamePrev)); strlcat(theLogFileName, gAppPrefix, ARRAY_SIZE(theLogFileNamePrev)); strlcat(theLogFileName, DEBUG_FILE_NAME, ARRAY_SIZE(theLogFileNamePrev)); if (rts::ClientInstance::getInstanceId() > 1u) @@ -736,9 +736,9 @@ void ReleaseCrash(const char *reason) return; // We are shutting down, and TheGlobalData has been freed. jba. [4/15/2003] } - strcpy(prevbuf, TheGlobalData->getPath_UserData().str()); + strlcpy(prevbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(prevbuf)); strlcat(prevbuf, RELEASECRASH_FILE_NAME_PREV, ARRAY_SIZE(prevbuf)); - strcpy(curbuf, TheGlobalData->getPath_UserData().str()); + strlcpy(curbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(curbuf)); strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf)); remove(prevbuf); @@ -825,9 +825,9 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m) char prevbuf[ _MAX_PATH ]; char curbuf[ _MAX_PATH ]; - strcpy(prevbuf, TheGlobalData->getPath_UserData().str()); + strlcpy(prevbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(prevbuf)); strlcat(prevbuf, RELEASECRASH_FILE_NAME_PREV, ARRAY_SIZE(prevbuf)); - strcpy(curbuf, TheGlobalData->getPath_UserData().str()); + strlcpy(curbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(curbuf)); strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf)); remove(prevbuf); diff --git a/Core/GameEngine/Source/Common/System/GameMemory.cpp b/Core/GameEngine/Source/Common/System/GameMemory.cpp index 8fcf71b138..26a4aa6619 100644 --- a/Core/GameEngine/Source/Common/System/GameMemory.cpp +++ b/Core/GameEngine/Source/Common/System/GameMemory.cpp @@ -2975,7 +2975,7 @@ void MemoryPoolFactory::memoryPoolUsageReport( const char* filename, FILE *appen if( !appendToFileInstead ) { char tmp[256]; - strcpy(tmp,filename); + strlcpy(tmp, filename, ARRAY_SIZE(tmp)); strlcat(tmp, ".csv", ARRAY_SIZE(tmp)); perfStatsFile = fopen(tmp, "w"); } diff --git a/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp b/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp index 9cacda79bf..0195bd4440 100644 --- a/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp +++ b/Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp @@ -227,7 +227,7 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect std::replace(fixedDirectory.begin(), fixedDirectory.end(), '\\', '/'); #endif - strcpy(search, fixedDirectory.c_str()); + strlcpy(search, fixedDirectory.c_str(), ARRAY_SIZE(search)); Bool done = FALSE; std::error_code ec; diff --git a/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp b/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp index 49e8b8de1a..e79965190c 100644 --- a/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp +++ b/Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp @@ -132,7 +132,7 @@ void Win32LocalFileSystem::getFileListInDirectory(const AsciiString& currentDire asciisearch = originalDirectory; asciisearch.concat(currentDirectory); asciisearch.concat(searchName); - strcpy(search, asciisearch.str()); + strlcpy(search, asciisearch.str(), ARRAY_SIZE(search)); Bool done = FALSE; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp b/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp index a38b30408b..815e59d9ca 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp @@ -255,7 +255,7 @@ int HCompressedAnimClass::Load_W3D(ChunkLoadClass & cload) cload.Close_Chunk(); - strcpy(Name,aheader.HierarchyName); + strlcpy(Name, aheader.HierarchyName, ARRAY_SIZE(Name)); strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, aheader.Name, ARRAY_SIZE(Name)); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp b/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp index dadf97e65b..602907b9f1 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp @@ -150,7 +150,7 @@ int HModelDefClass::Load_W3D(ChunkLoadClass & cload) */ strlcpy(ModelName,header.Name,W3D_NAME_LEN); strlcpy(BasePoseName,header.HierarchyName,W3D_NAME_LEN); - strcpy(Name,ModelName); + strlcpy(Name, ModelName, ARRAY_SIZE(Name)); /* ** Just allocate a node for the number of sub objects we're expecting @@ -232,7 +232,7 @@ bool HModelDefClass::read_connection(ChunkLoadClass & cload,HmdlNodeDefStruct * return false; } - strcpy(node->RenderObjName,ModelName); + strlcpy(node->RenderObjName, ModelName, ARRAY_SIZE(node->RenderObjName)); strlcat(node->RenderObjName, ".", ARRAY_SIZE(node->RenderObjName)); strlcat(node->RenderObjName, con.RenderObjName, ARRAY_SIZE(node->RenderObjName)); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp index f5fc0417a2..64299703f2 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp @@ -503,7 +503,7 @@ void RingRenderObjClass::Set_Name(const char * name) { WWASSERT(name != NULL); WWASSERT(strlen(name) < 2*W3D_NAME_LEN); - strcpy(Name,name); + strlcpy(Name, name, ARRAY_SIZE(Name)); } /*********************************************************************************************** @@ -1206,7 +1206,7 @@ RingPrototypeClass::RingPrototypeClass (void) RingPrototypeClass::RingPrototypeClass(RingRenderObjClass *ring) { ::memset (&Definition, 0, sizeof (Definition)); - ::strcpy (Definition.Name, ring->Get_Name ()); + strlcpy(Definition.Name, ring->Get_Name(), ARRAY_SIZE(Definition.Name)); Definition.AnimDuration = ring->AnimDuration; Definition.Attributes = ring->Get_Flags (); @@ -1237,7 +1237,7 @@ RingPrototypeClass::RingPrototypeClass(RingRenderObjClass *ring) filename = name; } - ::strcpy (Definition.TextureName, filename); + strlcpy(Definition.TextureName, filename, ARRAY_SIZE(Definition.TextureName)); } // diff --git a/Core/Libraries/Source/WWVegas/WW3D2/sphereobj.cpp b/Core/Libraries/Source/WWVegas/WW3D2/sphereobj.cpp index bd3514e747..3b24f5e09d 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/sphereobj.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/sphereobj.cpp @@ -437,8 +437,8 @@ const char * SphereRenderObjClass::Get_Name(void) const void SphereRenderObjClass::Set_Name(const char * name) { WWASSERT(name != NULL); - WWASSERT(strlen(name) < 2*W3D_NAME_LEN); - strcpy(Name,name); + const size_t nameLen = strlcpy(Name, name, ARRAY_SIZE(Name)); + (void)nameLen; WWASSERT(nameLen < ARRAY_SIZE(Name)); } @@ -1162,7 +1162,7 @@ SpherePrototypeClass::SpherePrototypeClass (void) SpherePrototypeClass::SpherePrototypeClass(SphereRenderObjClass *sphere) { ::memset (&Definition, 0, sizeof (Definition)); - ::strcpy (Definition.Name, sphere->Get_Name ()); + strlcpy(Definition.Name, sphere->Get_Name(), ARRAY_SIZE(Definition.Name)); Definition.DefaultAlpha = sphere->Get_Default_Alpha (); Definition.AnimDuration = sphere->AnimDuration; @@ -1190,7 +1190,7 @@ SpherePrototypeClass::SpherePrototypeClass(SphereRenderObjClass *sphere) filename = name; } - ::strcpy (Definition.TextureName, filename); + strlcpy(Definition.TextureName, filename, ARRAY_SIZE(Definition.TextureName)); } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp b/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp index 81659faabf..e6a7e5df3f 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp @@ -533,8 +533,8 @@ static void Get_W3D_Name (const char *filename, char *w3d_name) // Copy all characters from start to end (excluding 'end') // into the w3d_name buffer. Then capitalize the string. int num_chars = end - start; - WWASSERT(num_chars <= W3D_NAME_LEN); - strlcpy(w3d_name, start, min(W3D_NAME_LEN, num_chars)); + const size_t nameLen = strlcpy(w3d_name, start, min(W3D_NAME_LEN, num_chars)); + (void)nameLen; WWASSERT(nameLen < min(W3D_NAME_LEN, num_chars)); strupr(w3d_name); } @@ -565,7 +565,7 @@ static const char * Make_W3D_Filename (const char *w3d_name) buffer[0] = 0; return buffer; } - strcpy(buffer, w3d_name); + strlcpy(buffer, w3d_name, ARRAY_SIZE(buffer)); char *dot = strchr(buffer, '.'); if (dot) *dot = 0; diff --git a/Core/Libraries/Source/WWVegas/WWDownload/FTP.cpp b/Core/Libraries/Source/WWVegas/WWDownload/FTP.cpp index 94ec07d8d9..01e67957ea 100644 --- a/Core/Libraries/Source/WWVegas/WWDownload/FTP.cpp +++ b/Core/Libraries/Source/WWVegas/WWDownload/FTP.cpp @@ -1719,7 +1719,7 @@ HRESULT Cftp::FileRecoveryPosition( LPCSTR szLocalFileName, LPCSTR szRegistryRo // Concatenate the registry key together - strcpy( regkey, szRegistryRoot ); + strlcpy(regkey, szRegistryRoot, ARRAY_SIZE(regkey)); if( regkey[ strlen( regkey ) - 1 ] != '\\' ) { strlcat(regkey, "\\Download", ARRAY_SIZE(regkey)); diff --git a/Core/Libraries/Source/WWVegas/WWLib/Except.cpp b/Core/Libraries/Source/WWVegas/WWLib/Except.cpp index fe9e303638..e49d6ffb0e 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/Except.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/Except.cpp @@ -903,7 +903,7 @@ void Register_Thread_ID(unsigned long thread_id, char *thread_name, bool main_th ThreadInfoType *thread = new ThreadInfoType; thread->ThreadID = thread_id; - strcpy(thread->ThreadName, thread_name); + strlcpy(thread->ThreadName, thread_name, ARRAY_SIZE(thread->ThreadName)); thread->Main = main_thread; thread->ThreadHandle = INVALID_HANDLE_VALUE; ThreadList.Add(thread); diff --git a/Core/Libraries/Source/WWVegas/WWLib/ffactory.cpp b/Core/Libraries/Source/WWVegas/WWLib/ffactory.cpp index 308d5e5e6a..02ea652aea 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/ffactory.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/ffactory.cpp @@ -146,7 +146,7 @@ void SimpleFileFactoryClass::Prepend_Sub_Directory( const char * sub_directory ) // Ensure sub_directory ends with a slash, and append a semicolon char temp_sub_dir[1024]; - strcpy(temp_sub_dir, sub_directory); + strlcpy(temp_sub_dir, sub_directory, ARRAY_SIZE(temp_sub_dir)); if (temp_sub_dir[sub_len - 1] != '\\') { temp_sub_dir[sub_len] = '\\'; temp_sub_dir[sub_len + 1] = 0; @@ -181,7 +181,7 @@ void SimpleFileFactoryClass::Append_Sub_Directory( const char * sub_directory ) // Ensure sub_directory ends with a slash char temp_sub_dir[1024]; - strcpy(temp_sub_dir, sub_directory); + strlcpy(temp_sub_dir, sub_directory, ARRAY_SIZE(temp_sub_dir)); if (temp_sub_dir[sub_len - 1] != '\\') { temp_sub_dir[sub_len] = '\\'; temp_sub_dir[sub_len + 1] = 0; diff --git a/Core/Libraries/Source/WWVegas/WWLib/ini.cpp b/Core/Libraries/Source/WWVegas/WWLib/ini.cpp index 62ad143e0c..d6659b6859 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/ini.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/ini.cpp @@ -430,7 +430,7 @@ int INIClass::Load(Straw & ffile) if (ptr != NULL) *ptr = '\0'; strtrim(buffer); char section[64]; - strcpy(section, buffer); + strlcpy(section, buffer, ARRAY_SIZE(section)); /* ** Read in the entries of this section. diff --git a/Core/Libraries/Source/WWVegas/WWLib/registry.cpp b/Core/Libraries/Source/WWVegas/WWLib/registry.cpp index de172c5f49..15ec71602f 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/registry.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/registry.cpp @@ -470,7 +470,7 @@ void RegistryClass::Save_Registry_Tree(char *path, INIClass *ini) ** See if there are sub keys. */ char new_key_path[512]; - strcpy(new_key_path, path); + strlcpy(new_key_path, path, ARRAY_SIZE(new_key_path)); strlcat(new_key_path, "\\", ARRAY_SIZE(new_key_path)); strlcat(new_key_path, name, ARRAY_SIZE(new_key_path)); @@ -564,7 +564,7 @@ void RegistryClass::Load_Registry(const char *filename, char *old_path, char *ne ** Build the new path to use in the registry. */ char *section_name = section->Section; - strcpy(path, new_path); + strlcpy(path, new_path, ARRAY_SIZE(path)); char *cut = strstr(section_name, old_path); if (cut) { strlcat(path, cut + old_path_len, ARRAY_SIZE(path)); @@ -693,7 +693,7 @@ void RegistryClass::Delete_Registry_Tree(char *path) ** See if there are sub keys. */ char new_key_path[512]; - strcpy(new_key_path, path); + strlcpy(new_key_path, path, ARRAY_SIZE(new_key_path)); strlcat(new_key_path, "\\", ARRAY_SIZE(new_key_path)); strlcat(new_key_path, name, ARRAY_SIZE(new_key_path)); diff --git a/Core/Libraries/Source/WWVegas/WWLib/thread.cpp b/Core/Libraries/Source/WWVegas/WWLib/thread.cpp index d6cefc030b..6cbb50d84d 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/thread.cpp +++ b/Core/Libraries/Source/WWVegas/WWLib/thread.cpp @@ -34,8 +34,8 @@ ThreadClass::ThreadClass(const char *thread_name, ExceptionHandlerType exception_handler) : handle(0), running(false), thread_priority(0) { if (thread_name) { - assert(strlen(thread_name) < sizeof(ThreadName) - 1); - strcpy(ThreadName, thread_name); + size_t nameLen = strlcpy(ThreadName, thread_name, ARRAY_SIZE(ThreadName)); + (void)nameLen; assert(nameLen < ARRAY_SIZE(ThreadName)); } else { strcpy(ThreadName, "No name");; } diff --git a/Core/Libraries/Source/debug/debug_debug.cpp b/Core/Libraries/Source/debug/debug_debug.cpp index 27e412e55c..5bc38c7c5b 100644 --- a/Core/Libraries/Source/debug/debug_debug.cpp +++ b/Core/Libraries/Source/debug/debug_debug.cpp @@ -1188,7 +1188,7 @@ void Debug::UpdateFrameStatus(FrameHashEntry &entry) entry.frameType==FrameTypeCheck) wsprintf(help,"%s(%i)",entry.fileOrGroup,entry.line); else - strcpy(help,entry.fileOrGroup); + strlcpy(help, entry.fileOrGroup, ARRAY_SIZE(help)); // update frame status bool active=entry.frameType!=FrameTypeLog; diff --git a/Core/Libraries/Source/debug/debug_io_flat.cpp b/Core/Libraries/Source/debug/debug_io_flat.cpp index f78a5e7059..1343bd6693 100644 --- a/Core/Libraries/Source/debug/debug_io_flat.cpp +++ b/Core/Libraries/Source/debug/debug_io_flat.cpp @@ -83,17 +83,15 @@ void DebugIOFlat::OutputStream::Delete(const char *path) char help[512]; if (path[0]&&(path[1]==':'||(path[0]=='\\'&&path[1]=='\\'))) { - strcpy(help,path); - strcpy(help+pathLen,fileNameOnly); - help[ext-fileNameOnly+pathLen]=0; + strlcpy(help, path, ARRAY_SIZE(help)); + strlcat(help, fileNameOnly, ARRAY_SIZE(help)); } else { // no, relative path given - strcpy(help,m_fileName); - strcpy(help+(fileNameOnly-m_fileName),path); - strcpy(help+(fileNameOnly-m_fileName)+pathLen,fileNameOnly); - help[ext-fileNameOnly+pathLen+(fileNameOnly-m_fileName)]=0; + strlcpy(help, m_fileName, ARRAY_SIZE(help)); + strlcat(help, path, ARRAY_SIZE(help)); + strlcat(help, fileNameOnly, ARRAY_SIZE(help)); } if (++run) wsprintf(help+strlen(help),"(%i)%s",run,ext); @@ -268,7 +266,7 @@ void DebugIOFlat::ExpandMagic(const char *src, const char *splitName, char *buf) case 'n': case 'N': if (splitName&&strlen(splitName)<250) - strcpy(help,splitName); + strlcpy(help, splitName, ARRAY_SIZE(help)); break; default: *dst++=src[-1]; @@ -277,7 +275,7 @@ void DebugIOFlat::ExpandMagic(const char *src, const char *splitName, char *buf) unsigned len=strlen(help); if (dst-buf+len>250) break; - strcpy(dst,help); + strlcpy(dst, help, ARRAY_SIZE(dst)); dst+=len; } strcpy(dst,".log"); @@ -418,7 +416,7 @@ void DebugIOFlat::Execute(class Debug& dbg, const char *cmd, bool structuredCmd, // add [ [ ] ] __ASSERT(m_firstStream==NULL); - strcpy(m_baseFilename,argn?argv[0]:"*eMN"); + strlcpy(m_baseFilename, argn?argv[0]:"*eMN", ARRAY_SIZE(m_baseFilename)); char fn[256]; ExpandMagic(m_baseFilename,NULL,fn); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp index 13e02c692b..29a5a687e0 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp @@ -411,7 +411,7 @@ UnsignedInt INI::load( AsciiString filename, INILoadType loadType, Xfer *pXfer ) if (parse) { #ifdef DEBUG_CRASHING - strcpy(m_curBlockStart, m_buffer); + strlcpy(m_curBlockStart, m_buffer, ARRAY_SIZE(m_curBlockStart)); #endif try { (*parse)( this ); @@ -768,7 +768,7 @@ AsciiString INI::getNextQuotedAsciiString() Bool done=FALSE; if ((strLen=strlen(token)) > 1) { - strcpy(buff, &token[1]); //skip the starting quote + strlcpy(buff, &token[1], ARRAY_SIZE(buff)); //skip the starting quote //Check for end of quoted string. Checking here fixes cases where quoted string on same line with other data. if (buff[strLen-2]=='"') //skip ending quote if present { buff[strLen-2]='\0'; @@ -817,7 +817,7 @@ AsciiString INI::getNextAsciiString() buff[0] = 0; if (strlen(token) > 1) { - strcpy(buff, &token[1]); + strlcpy(buff, &token[1], ARRAY_SIZE(buff)); } token = getNextTokenOrNull(getSepsQuote()); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp index 72fc4837ca..fe069abfb3 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/PerfTimer.cpp @@ -349,10 +349,10 @@ void PerfGather::reset() { PerfGather::termPerfDump(); - strcpy(s_buf, fname); + strlcpy(s_buf, fname, _MAX_PATH); char tmp[256]; - strcpy(tmp, s_buf); + strlcpy(tmp, s_buf, ARRAY_SIZE(tmp)); strlcat(tmp, ".csv", ARRAY_SIZE(tmp)); s_perfStatsFile = fopen(tmp, "w"); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp index acfe4e3aa3..b961d2e24e 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp @@ -847,14 +847,15 @@ static AsciiString getMapLeafAndDirName(const AsciiString& in) // ------------------------------------------------------------------------------------------------ static AsciiString removeExtension(const AsciiString& in) { - char buf[1024]; - strcpy(buf, in.str()); - char* p = strrchr(buf, '.'); - if (p) + if (const char* end = in.reverseFind('.')) { - *p = 0; + const char* begin = in.str(); + return AsciiString(begin, end - begin); + } + else + { + return in; } - return AsciiString(buf); } // ------------------------------------------------------------------------------------------------ @@ -1623,7 +1624,7 @@ void GameState::xfer( Xfer *xfer ) { char string[ _MAX_PATH ]; - strcpy( string, TheGlobalData->m_mapName.str() ); + strlcpy(string, TheGlobalData->m_mapName.str(), ARRAY_SIZE(string)); char *p = strrchr( string, '\\' ); if( p == NULL ) saveGameInfo->mapLabel = TheGlobalData->m_mapName; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp index 75900159d6..bb8190edd9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/NetworkDirectConnect.cpp @@ -219,11 +219,9 @@ void JoinDirectConnectGame() AsciiString ipstring; asciientry.nextToken(&ipstring, "("); - char ipstr[16]; - strcpy(ipstr, ipstring.str()); - Int ip1, ip2, ip3, ip4; - sscanf(ipstr, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4); + Int numFields = sscanf(ipstring.str(), "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4); + (void)numFields; DEBUG_ASSERTCRASH(numFields == 4, ("JoinDirectConnectGame - invalid IP address format: %s", ipstring.str())); DEBUG_LOG(("JoinDirectConnectGame - joining at %d.%d.%d.%d", ip1, ip2, ip3, ip4)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp index 5420b57723..d838f93715 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLoginMenu.cpp @@ -1260,9 +1260,9 @@ WindowMsgHandledType WOLLoginMenuSystem( GameWindow *window, UnsignedInt msg, loginAttemptTime = timeGetTime(); BuddyRequest req; req.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGINNEW; - strcpy(req.arg.login.nick, login.str()); - strcpy(req.arg.login.email, email.str()); - strcpy(req.arg.login.password, password.str()); + strlcpy(req.arg.login.nick, login.str(), ARRAY_SIZE(req.arg.login.nick)); + strlcpy(req.arg.login.email, email.str(), ARRAY_SIZE(req.arg.login.email)); + strlcpy(req.arg.login.password, password.str(), ARRAY_SIZE(req.arg.login.password)); req.arg.login.hasFirewall = TRUE; TheGameSpyInfo->setLocalBaseName( login ); @@ -1349,9 +1349,9 @@ WindowMsgHandledType WOLLoginMenuSystem( GameWindow *window, UnsignedInt msg, loginAttemptTime = timeGetTime(); BuddyRequest req; req.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGIN; - strcpy(req.arg.login.nick, login.str()); - strcpy(req.arg.login.email, email.str()); - strcpy(req.arg.login.password, password.str()); + strlcpy(req.arg.login.nick, login.str(), ARRAY_SIZE(req.arg.login.nick)); + strlcpy(req.arg.login.email, email.str(), ARRAY_SIZE(req.arg.login.email)); + strlcpy(req.arg.login.password, password.str(), ARRAY_SIZE(req.arg.login.password)); req.arg.login.hasFirewall = true; TheGameSpyInfo->setLocalBaseName( login ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp index 51b25e8045..370cd8fee6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp @@ -232,7 +232,7 @@ static void parseBitString( const char *inBuffer, UnsignedInt *bits, ConstCharPt char *tok; // do not modify the inBuffer argument - strcpy( buffer, inBuffer ); + strlcpy(buffer, inBuffer, ARRAY_SIZE(buffer)); if( strncmp( buffer, "NULL", 4 ) ) { @@ -605,7 +605,7 @@ static Bool parseFont( const char *token, WinInstanceData *instData, ptr++; ptr++; // skip the " c = strtok( ptr, stringSeps ); // value - strcpy( fontName, c ); + strlcpy(fontName, c, ARRAY_SIZE(fontName)); // "SIZE" c = strtok( NULL, seps ); // label @@ -1649,7 +1649,7 @@ static GameWindow *createGadget( char *type, // filename the radio button was saved in // - strcpy( filename, instData->m_decoratedNameString.str() ); + strlcpy(filename, instData->m_decoratedNameString.str(), ARRAY_SIZE(filename)); c = strchr( filename, ':' ); if( c ) *c = 0; // terminate after filename (format is filename:gadgetname) @@ -2373,7 +2373,7 @@ static GameWindow *parseWindow( File *inFile, char *buffer ) c = strtok( buffer, seps ); assert( strcmp( c, "WINDOWTYPE" ) == 0 ); c = strtok( NULL, seps ); // get data to right of = sign - strcpy( type, c ); + strlcpy(type, c, ARRAY_SIZE(type)); // // based on the window type get a pointer for any specific data @@ -2402,7 +2402,7 @@ static GameWindow *parseWindow( File *inFile, char *buffer ) if (asciibuf.compare(parse->name) == 0) { - strcpy( token, asciibuf.str() ); + strlcpy(token, asciibuf.str(), ARRAY_SIZE(token)); // eat '=' inFile->scanString(asciibuf); @@ -2618,7 +2618,7 @@ Bool parseLayoutBlock( File *inFile, char *buffer, UnsignedInt version, WindowLa // eat equals separator " = " c = strtok( buffer, " =" ); - strcpy(token, asciitoken.str()); + strlcpy(token, asciitoken.str(), ARRAY_SIZE(token)); // parse it if( parse->parse( token, c, version, info ) == FALSE ) @@ -2727,7 +2727,7 @@ GameWindow *GameWindowManager::winCreateFromScript( AsciiString filenameString, if( strchr( filename, '\\' ) == NULL ) sprintf( filepath, "Window\\%s", filename ); else - strcpy( filepath, filename ); + strlcpy(filepath, filename, ARRAY_SIZE(filepath)); // Open the input file inFile = TheFileSystem->openFile(filepath, File::READ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp index 69fe64e6c6..d92a6b5ef0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp @@ -73,7 +73,7 @@ void RadiusDecalTemplate::createRadiusDecal(const Coord3D& pos, Real radius, con decalInfo.allowUpdates = FALSE; // shadow texture will never update decalInfo.allowWorldAlign = TRUE; // shadow image will wrap around world objects decalInfo.m_type = m_shadowType; - strcpy(decalInfo.m_ShadowName, m_name.str()); // name of your texture + strlcpy(decalInfo.m_ShadowName, m_name.str(), ARRAY_SIZE(decalInfo.m_ShadowName)); // name of your texture decalInfo.m_sizeX = radius*2; // world space dimensions decalInfo.m_sizeY = radius*2; // world space dimensions diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp index 0967db847b..7bbe1d9024 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp @@ -2627,11 +2627,10 @@ void ScriptActions::doDisplayCinematicText(const AsciiString& displayText, const // get the font name AsciiString fontName = AsciiString::TheEmptyString; - char buf[256]; - char *c; - strcpy(buf, fontType.str()); + // TheSuperHackers @fix xezon 16/03/2025 Fixes potential buffer overrun via prior c!='\0' test. - for( c = buf; *c != '\0'; c++ ) + const char* c = fontType.str(); + for (; *c != '\0'; c++) { if( *c != ' ' && *c++ != '-' ) fontName.concat(c); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp index 2c7057c02e..ebe7086a9e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp @@ -2136,8 +2136,9 @@ Parameter *Parameter::ReadParameter(DataChunkInput &file) { char oldName[256]; char newName[256]; - strcpy(oldName, pParm->m_string.str()); + strlcpy(oldName, pParm->m_string.str(), ARRAY_SIZE(oldName)); strcpy(newName, "GLA"); + static_assert(ARRAY_SIZE(oldName) >= ARRAY_SIZE("GLA"), "oldname buffer too small"); strlcat(newName, oldName+strlen("Fundamentalist"), ARRAY_SIZE(newName)); pParm->m_string.set(newName); DEBUG_LOG(("Changing Script Ref from %s to %s", oldName, newName)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 8ce2a5069b..b920b79fe5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -2466,17 +2466,17 @@ void GameLogic::loadMapINI( AsciiString mapName ) char filename[_MAX_PATH]; char fullFledgeFilename[_MAX_PATH]; - memset(filename, 0, _MAX_PATH); - strcpy(filename, mapName.str()); - // // if map name begins with a "SAVE_DIRECTORY\", then the map refers to a map // that has been extracted from a save game file ... in that case we need to get // the pristine map name string in order to manipulate and load the right map.ini // for that map from it's original location // - if (TheGameState->isInSaveDirectory(filename)) - strcpy( filename, TheGameState->getSaveGameInfo()->pristineMapName.str() ); + const char* pristineMapName = TheGameState->isInSaveDirectory(filename) + ? TheGameState->getSaveGameInfo()->pristineMapName.str() + : mapName.str(); + + strlcpy(filename, pristineMapName, ARRAY_SIZE(filename)); // sanity int length = strlen(filename); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp index 7cef7ea437..0567789e29 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/FirewallHelper.cpp @@ -679,9 +679,7 @@ Bool FirewallHelperClass::detectionBeginUpdate() { /* ** Do the lookup. */ - char temp_name[256]; - strcpy(temp_name, mangler_name_ptr); - struct hostent *host_info = gethostbyname(temp_name); + struct hostent* host_info = gethostbyname(mangler_name_ptr); if (!host_info) { DEBUG_LOG(("gethostbyname failed! Error code %d", WSAGetLastError())); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp index 832eb912d5..7835a7ef59 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp @@ -504,6 +504,7 @@ void BuddyThreadClass::errorCallback( GPConnection *con, GPErrorArg *arg ) static void getNickForMessage( GPConnection *con, GPGetInfoResponseArg *arg, void *param ) { BuddyResponse *resp = (BuddyResponse *)param; + static_assert(ARRAY_SIZE(arg->nick) <= ARRAY_SIZE(resp->arg.message.nick), "Incorrect array size"); strcpy(resp->arg.message.nick, arg->nick); } @@ -557,8 +558,11 @@ void BuddyThreadClass::connectCallback( GPConnection *con, GPConnectResponseArg DEBUG_LOG(("User Error: Create Account instead of Login. Fixing them...")); BuddyRequest req; req.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGIN; + static_assert(ARRAY_SIZE(req.arg.login.nick) > 0, "Array size too small"); strcpy(req.arg.login.nick, m_nick.c_str()); + static_assert(ARRAY_SIZE(req.arg.login.email) > 0, "Array size too small"); strcpy(req.arg.login.email, m_email.c_str()); + static_assert(ARRAY_SIZE(req.arg.login.password) > 0, "Array size too small"); strcpy(req.arg.login.password, m_pass.c_str()); req.arg.login.hasFirewall = true; TheGameSpyBuddyMessageQueue->addRequest( req ); @@ -618,8 +622,11 @@ static void getInfoResponseForRequest( GPConnection *con, GPGetInfoResponseArg * { BuddyResponse *resp = (BuddyResponse *)param; resp->profile = arg->profile; + static_assert(ARRAY_SIZE(arg->nick) <= ARRAY_SIZE(resp->arg.request.nick), "Incorrect array size"); strcpy(resp->arg.request.nick, arg->nick); + static_assert(ARRAY_SIZE(arg->email) <= ARRAY_SIZE(resp->arg.request.email), "Incorrect array size"); strcpy(resp->arg.request.email, arg->email); + static_assert(ARRAY_SIZE(arg->countrycode) <= ARRAY_SIZE(resp->arg.request.countrycode), "Incorrect array size"); strcpy(resp->arg.request.countrycode, arg->countrycode); } @@ -644,8 +651,11 @@ static void getInfoResponseForStatus(GPConnection * connection, GPGetInfoRespons { BuddyResponse *resp = (BuddyResponse *)param; resp->profile = arg->profile; + static_assert(ARRAY_SIZE(arg->nick) <= ARRAY_SIZE(resp->arg.status.nick), "Incorrect array size"); strcpy(resp->arg.status.nick, arg->nick); + static_assert(ARRAY_SIZE(arg->email) <= ARRAY_SIZE(resp->arg.status.email), "Incorrect array size"); strcpy(resp->arg.status.email, arg->email); + static_assert(ARRAY_SIZE(arg->countrycode) <= ARRAY_SIZE(resp->arg.status.countrycode), "Incorrect array size"); strcpy(resp->arg.status.countrycode, arg->countrycode); } @@ -660,7 +670,9 @@ void BuddyThreadClass::statusCallback( GPConnection *con, GPRecvBuddyStatusArg * // get user's status GPBuddyStatus status; gpGetBuddyStatus( con, arg->index, &status ); + static_assert(ARRAY_SIZE(status.locationString) <= ARRAY_SIZE(response.arg.status.location), "Incorrect array size"); strcpy(response.arg.status.location, status.locationString); + static_assert(ARRAY_SIZE(status.statusString) <= ARRAY_SIZE(response.arg.status.statusString), "Incorrect array size"); strcpy(response.arg.status.statusString, status.statusString); response.arg.status.status = status.status; DEBUG_LOG(("Got buddy status for %d(%s) - status %d", status.profile, response.arg.status.nick, status.status)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp index 58dc8a3cd5..d6f6cf98c1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp @@ -127,15 +127,12 @@ UDP::~UDP() Int UDP::Bind(const char *Host,UnsignedShort port) { - char hostName[100]; struct hostent *hostStruct; struct in_addr *hostNode; if (isdigit(Host[0])) return ( Bind( ntohl(inet_addr(Host)), port) ); - strcpy(hostName, Host); - hostStruct = gethostbyname(Host); if (hostStruct == NULL) return (0); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index ba994253f3..ca4b86b88c 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -1859,7 +1859,7 @@ void W3DModelDraw::allocateShadows(void) if (m_shadow == NULL && m_renderObject && TheW3DShadowManager && tmplate->getShadowType() != SHADOW_NONE) { Shadow::ShadowTypeInfo shadowInfo; - strcpy(shadowInfo.m_ShadowName, tmplate->getShadowTextureName().str()); + strlcpy(shadowInfo.m_ShadowName, tmplate->getShadowTextureName().str(), ARRAY_SIZE(shadowInfo.m_ShadowName)); DEBUG_ASSERTCRASH(shadowInfo.m_ShadowName[0] != '\0', ("this should be validated in ThingTemplate now")); shadowInfo.allowUpdates = FALSE; //shadow image will never update shadowInfo.allowWorldAlign = TRUE; //shadow image will wrap around world objects @@ -2751,9 +2751,9 @@ void W3DModelDraw::setTerrainDecal(TerrainDecalType type) //decalInfo.m_type = SHADOW_ADDITIVE_DECAL;//temporary kluge to test graphics if (type == TERRAIN_DECAL_SHADOW_TEXTURE) - strcpy(decalInfo.m_ShadowName,tmplate->getShadowTextureName().str()); + strlcpy(decalInfo.m_ShadowName, tmplate->getShadowTextureName().str(), ARRAY_SIZE(decalInfo.m_ShadowName)); else - strcpy(decalInfo.m_ShadowName,TerrainDecalTextureName[type]); + strlcpy(decalInfo.m_ShadowName, TerrainDecalTextureName[type], ARRAY_SIZE(decalInfo.m_ShadowName)); decalInfo.m_sizeX = tmplate->getShadowSizeX(); decalInfo.m_sizeY = tmplate->getShadowSizeY(); decalInfo.m_offsetX = tmplate->getShadowOffsetX(); @@ -3069,7 +3069,7 @@ void W3DModelDraw::setModelState(const ModelConditionInfo* newState) if (m_renderObject && TheW3DShadowManager && tmplate->getShadowType() != SHADOW_NONE) { Shadow::ShadowTypeInfo shadowInfo; - strcpy(shadowInfo.m_ShadowName, tmplate->getShadowTextureName().str()); + strlcpy(shadowInfo.m_ShadowName, tmplate->getShadowTextureName().str(), ARRAY_SIZE(shadowInfo.m_ShadowName)); DEBUG_ASSERTCRASH(shadowInfo.m_ShadowName[0] != '\0', ("this should be validated in ThingTemplate now")); shadowInfo.allowUpdates = FALSE; //shadow image will never update shadowInfo.allowWorldAlign = TRUE; //shadow image will wrap around world objects @@ -3455,7 +3455,7 @@ Int W3DModelDraw::getPristineBonePositionsForConditionState( for (; i <= endIndex; ++i) { if (i == 0) - strcpy(buffer, boneNamePrefix); + strlcpy(buffer, boneNamePrefix, ARRAY_SIZE(buffer)); else sprintf(buffer, "%s%02d", boneNamePrefix, i); @@ -3612,7 +3612,7 @@ Int W3DModelDraw::getCurrentBonePositions( for (; i <= endIndex; ++i) { if (i == 0) - strcpy(buffer, boneNamePrefix); + strlcpy(buffer, boneNamePrefix, ARRAY_SIZE(buffer)); else sprintf(buffer, "%s%02d", boneNamePrefix, i); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp index 33c0782c72..534a144018 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp @@ -1718,6 +1718,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S //onto world geometry. if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object { + static_assert(ARRAY_SIZE(defaultDecalName) < ARRAY_SIZE(texture_name), "Incorrect array size"); strcpy(texture_name, defaultDecalName); } else @@ -1763,10 +1764,10 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S //to allow multiple models to share same shadow - for //example, all trees could use same shadow even if slightly //different color, etc. - strcpy(texture_name,shadowInfo->m_ShadowName); + strlcpy(texture_name, shadowInfo->m_ShadowName, ARRAY_SIZE(texture_name)); } else - strcpy(texture_name,robj->Get_Name()); //not texture name give, assume model name. + strlcpy(texture_name, robj->Get_Name(), ARRAY_SIZE(texture_name)); //not texture name give, assume model name. st=m_W3DShadowTextureManager->getTexture(texture_name); if (st == NULL) @@ -1785,7 +1786,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::addShadow(RenderObjClass *robj, S } else { //no shadow info, assume user wants a projected shadow - strcpy(texture_name,robj->Get_Name()); + strlcpy(texture_name, robj->Get_Name(), ARRAY_SIZE(texture_name)); st=m_W3DShadowTextureManager->getTexture(texture_name); @@ -1894,6 +1895,7 @@ W3DProjectedShadow* W3DProjectedShadowManager::createDecalShadow(Shadow::ShadowT //onto world geometry. if (strlen(shadowInfo->m_ShadowName) <= 1) //no texture name given, use same as object { + static_assert(ARRAY_SIZE(defaultDecalName) < ARRAY_SIZE(texture_name), "Incorrect array size"); strcpy(texture_name, defaultDecalName); } else diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp index b6d4111f7e..a27412e974 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -270,7 +270,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(const char* name) static inline void Munge_Render_Obj_Name(char *newname, const char *oldname, float scale, const int color, const char *textureName) { char lower_case_name[255]; - strcpy(lower_case_name, oldname); + strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name)); _strlwr(lower_case_name); if (!textureName) @@ -283,7 +283,7 @@ static inline void Munge_Render_Obj_Name(char *newname, const char *oldname, flo static inline void Munge_Texture_Name(char *newname, const char *oldname, const int color) { char lower_case_name[255]; - strcpy(lower_case_name, oldname); + strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name)); _strlwr(lower_case_name); sprintf(newname,"#%d#%s", color, lower_case_name); } @@ -975,7 +975,7 @@ bool W3DAssetManager::Load_3D_Assets( const char * filename ) // Try to find an existing prototype char basename[512]; - strcpy(basename, filename); + strlcpy(basename, filename, ARRAY_SIZE(basename)); char *pext = strrchr(basename, '.'); //find file extension if (pext) *pext = '\0'; //drop the extension @@ -1314,7 +1314,7 @@ void W3DAssetManager::Make_Unique(RenderObjClass *robj, Bool geometry, Bool colo static inline void Munge_Render_Obj_Name(char *newname, const char *oldname, float scale, const Vector3 &hsv_shift) { char lower_case_name[255]; - strcpy(lower_case_name, oldname); + strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name)); _strlwr(lower_case_name); sprintf(newname,"#%s!%gH%gS%gV%g", lower_case_name, scale, hsv_shift.X, hsv_shift.Y, hsv_shift.Z); } @@ -1322,7 +1322,7 @@ static inline void Munge_Render_Obj_Name(char *newname, const char *oldname, flo static inline void Munge_Texture_Name(char *newname, const char *oldname, const Vector3 &hsv_shift) { char lower_case_name[255]; - strcpy(lower_case_name, oldname); + strlcpy(lower_case_name, oldname, ARRAY_SIZE(lower_case_name)); _strlwr(lower_case_name); sprintf(newname,"#%s!H%gS%gV%g", lower_case_name, hsv_shift.X, hsv_shift.Y, hsv_shift.Z); } @@ -1345,7 +1345,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scal if (isGranny) { //Granny objects share the same prototype since they allow instance scaling. - strcpy(newname,name); //use same name for all granny objects at any scale. + strlcpy(newname, name, ARRAY_SIZE(newname)); //use same name for all granny objects at any scale. } Set_WW3D_Load_On_Demand(false); // munged name will never be found in a file. rendobj=WW3DAssetManager::Create_Render_Obj(newname); @@ -1451,7 +1451,7 @@ TextureClass * W3DAssetManager::Get_Texture_With_HSV_Shift(const char * filename // No cached texture - need to create char lower_case_name[255]; - strcpy(lower_case_name, filename); + strlcpy(lower_case_name, filename, ARRAY_SIZE(lower_case_name)); _strlwr(lower_case_name); TextureClass *oldtex = TextureHash.Get(lower_case_name); if (!oldtex) { diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp index 404d0f7196..1154619c02 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp @@ -212,20 +212,20 @@ Bool W3DBridge::load(BodyDamageType curDamageState) default: return false; case BODY_PRISTINE: - strcpy( textureFile, bridge->getTexture().str() ); - strcpy( modelName, bridge->getBridgeModel().str() ); + strlcpy(textureFile, bridge->getTexture().str(), ARRAY_SIZE(textureFile)); + strlcpy(modelName, bridge->getBridgeModel().str(), ARRAY_SIZE(modelName)); break; case BODY_DAMAGED: - strcpy( textureFile, bridge->getTextureDamaged().str() ); - strcpy( modelName, bridge->getBridgeModelNameDamaged().str() ); + strlcpy(textureFile, bridge->getTextureDamaged().str(), ARRAY_SIZE(textureFile)); + strlcpy(modelName, bridge->getBridgeModelNameDamaged().str(), ARRAY_SIZE(modelName)); break; case BODY_REALLYDAMAGED: - strcpy( textureFile, bridge->getTextureReallyDamaged().str() ); - strcpy( modelName, bridge->getBridgeModelNameReallyDamaged().str() ); + strlcpy(textureFile, bridge->getTextureReallyDamaged().str(), ARRAY_SIZE(textureFile)); + strlcpy(modelName, bridge->getBridgeModelNameReallyDamaged().str(), ARRAY_SIZE(modelName)); break; case BODY_RUBBLE: - strcpy( textureFile, bridge->getTextureBroken().str() ); - strcpy( modelName, bridge->getBridgeModelNameBroken().str() ); + strlcpy(textureFile, bridge->getTextureBroken().str(), ARRAY_SIZE(textureFile)); + strlcpy(modelName, bridge->getBridgeModelNameBroken().str(), ARRAY_SIZE(modelName)); break; } @@ -234,11 +234,11 @@ Bool W3DBridge::load(BodyDamageType curDamageState) char section[_MAX_PATH]; char right[_MAX_PATH]; - strcpy(left, modelName); + strlcpy(left, modelName, ARRAY_SIZE(left)); strlcat(left, ".BRIDGE_LEFT", ARRAY_SIZE(left)); - strcpy(section, modelName); + strlcpy(section, modelName, ARRAY_SIZE(section)); strlcat(section, ".BRIDGE_SPAN", ARRAY_SIZE(section)); - strcpy(right, modelName); + strlcpy(right, modelName, ARRAY_SIZE(right)); strlcat(right, ".BRIDGE_RIGHT", ARRAY_SIZE(right)); m_bridgeTexture = pMgr->Get_Texture(textureFile, MIP_LEVELS_3); @@ -254,15 +254,15 @@ Bool W3DBridge::load(BodyDamageType curDamageState) Matrix3D mtx = pSub->Get_Transform(); if (0==strnicmp(left, pSub->Get_Name(), strlen(left))) { m_leftMtx = mtx; - strcpy(left, pSub->Get_Name()); + strlcpy(left, pSub->Get_Name(), ARRAY_SIZE(left)); } if (0==strnicmp(section, pSub->Get_Name(), strlen(section))) { m_sectionMtx = mtx; - strcpy(section, pSub->Get_Name()); + strlcpy(section, pSub->Get_Name(), ARRAY_SIZE(section)); } if (0==strnicmp(right, pSub->Get_Name(), strlen(right))) { m_rightMtx = mtx; - strcpy(right, pSub->Get_Name()); + strlcpy(right, pSub->Get_Name(), ARRAY_SIZE(right)); } REF_PTR_RELEASE(pSub); //DEBUG_LOG(("Sub obj name %s", pSub->Get_Name())); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 61a20797cf..4491885365 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -3018,7 +3018,7 @@ void W3DDisplay::takeScreenShot(void) #else sprintf( leafname, "%s%.3d.bmp", "sshot", frame_number++); #endif - strcpy(pathname, TheGlobalData->getPath_UserData().str()); + strlcpy(pathname, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(pathname)); strlcat(pathname, leafname, ARRAY_SIZE(pathname)); if (_access( pathname, 0 ) == -1) done = true; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp index eae8ffc250..72d77be8dc 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DFileSystem.cpp @@ -197,19 +197,21 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_W3D ) { - strcpy( m_filePath, W3D_DIR_PATH ); + static_assert(ARRAY_SIZE(W3D_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size"); + strcpy(m_filePath, W3D_DIR_PATH); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else if( isImageFileType(fileType) ) { - strcpy( m_filePath, TGA_DIR_PATH ); + static_assert(ARRAY_SIZE(TGA_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size"); + strcpy(m_filePath, TGA_DIR_PATH); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else - strcpy( m_filePath, filename ); + strlcpy(m_filePath, filename, ARRAY_SIZE(m_filePath)); // see if the file exists m_fileExists = TheFileSystem->doesFileExist( m_filePath ); @@ -225,14 +227,16 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_W3D ) { - strcpy( m_filePath, LEGACY_W3D_DIR_PATH ); + static_assert(ARRAY_SIZE(LEGACY_W3D_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size"); + strcpy(m_filePath, LEGACY_W3D_DIR_PATH, ARRAY_SIZE(m_filePath)); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else if( isImageFileType(fileType) ) { - strcpy( m_filePath, LEGACY_TGA_DIR_PATH ); + static_assert(ARRAY_SIZE(LEGACY_TGA_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size"); + strcpy(m_filePath, LEGACY_TGA_DIR_PATH, ARRAY_SIZE(m_filePath)); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } @@ -253,14 +257,16 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_W3D ) { - strcpy( m_filePath, TEST_W3D_DIR_PATH ); + static_assert(ARRAY_SIZE(TEST_W3D_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size"); + strcpy(m_filePath, TEST_W3D_DIR_PATH); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else if( isImageFileType(fileType) ) { - strcpy( m_filePath, TEST_TGA_DIR_PATH ); + static_assert(ARRAY_SIZE(TEST_TGA_DIR_PATH) < ARRAY_SIZE(m_filePath), "Incorrect array size"); + strcpy(m_filePath, TEST_TGA_DIR_PATH); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } @@ -277,14 +283,12 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_W3D ) { sprintf(m_filePath,USER_W3D_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_W3D_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } else if( isImageFileType(fileType) ) { sprintf(m_filePath,USER_TGA_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_TGA_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } @@ -301,7 +305,6 @@ char const * GameFileClass::Set_Name( char const *filename ) if( fileType == FILE_TYPE_TGA ) // just TGA, since we don't do dds previews { sprintf(m_filePath,MAP_PREVIEW_DIR_PATH, TheGlobalData->getPath_UserData().str()); - //strcpy( m_filePath, USER_TGA_DIR_PATH ); strlcat(m_filePath, filename, ARRAY_SIZE(m_filePath)); } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp index 98c2556fbf..964eb896ac 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp @@ -960,10 +960,8 @@ void WaterTracksRenderSystem::saveTracks(void) AsciiString fileName=TheTerrainLogic->getSourceFilename(); char path[256]; - strcpy(path,fileName.str()); - Int len=strlen(path); - - strcpy(path+len-4,".wak"); + strlcpy(path, fileName.str(), ARRAY_SIZE(path)); + strlcat(path, ".wak", ARRAY_SIZE(path)); WaterTracksObj *umod; Int trackCount=0; @@ -998,10 +996,8 @@ void WaterTracksRenderSystem::loadTracks(void) AsciiString fileName=TheTerrainLogic->getSourceFilename(); char path[256]; - strcpy(path,fileName.str()); - Int len=strlen(path); - - strcpy(path+len-4,".wak"); + strlcpy(path, fileName.str(), ARRAY_SIZE(path)); + strlcat(path, ".wak", ARRAY_SIZE(path)); File *file = TheFileSystem->openFile(path, File::READ | File::BINARY); WaterTracksObj *umod; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp index 35b3c12824..e65d5f7c5a 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DTerrainLogic.cpp @@ -117,22 +117,6 @@ Bool W3DTerrainLogic::loadMap( AsciiString filename , Bool query ) WorldHeightMap *terrainHeightMap; ///< holds raw heightmap data samples - char tempBuf[_MAX_PATH]; - char filenameBuf[_MAX_PATH]; - int length = 0; - - strcpy(tempBuf, filename.str()); - - length = strlen( tempBuf ); - if( length >= 4 ) - { - strlcpy( filenameBuf, tempBuf, length - 4 + 1); - } - -// const char *fname = filename.reverseFind('\\'); -// if (fname) -// filename = fname+1; - CachedFileInputStream fileStrm; if ( !fileStrm.open(filename) ) { diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp index 5c72eab346..f2bb6637b5 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/boxrobj.cpp @@ -307,8 +307,8 @@ const char * BoxRenderObjClass::Get_Name(void) const void BoxRenderObjClass::Set_Name(const char * name) { WWASSERT(name != NULL); - WWASSERT(strlen(name) < 2*W3D_NAME_LEN); - strcpy(Name,name); + size_t nameLen = strlcpy(Name, name, ARRAY_SIZE(Name)); + (void)nameLen; WWASSERT(nameLen < ARRAY_SIZE(Name)); } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp index 03477b880d..75adccebfc 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp @@ -475,7 +475,7 @@ void HMorphAnimClass::Set_Name(const char * name) // // Copy the full name // - ::strcpy (Name, name); + strlcpy(Name, name, ARRAY_SIZE(Name)); // // Try to find the separator (a period) @@ -489,8 +489,8 @@ void HMorphAnimClass::Set_Name(const char * name) // into our two buffers // separator[0] = 0; - ::strcpy (AnimName, separator + 1); - ::strcpy (HierarchyName, full_name); + strlcpy(AnimName, separator + 1, ARRAY_SIZE(AnimName)); + strlcpy(HierarchyName, full_name, ARRAY_SIZE(HierarchyName)); } return ; @@ -548,9 +548,9 @@ int HMorphAnimClass::Load_W3D(ChunkLoadClass & cload) cload.Read(&header,sizeof(header)); cload.Close_Chunk(); - strlcpy(AnimName,header.Name,sizeof(AnimName)); - strlcpy(HierarchyName,header.HierarchyName,sizeof(HierarchyName)); - strcpy(Name,HierarchyName); + strlcpy(AnimName, header.Name, ARRAY_SIZE(AnimName)); + strlcpy(HierarchyName, header.HierarchyName, ARRAY_SIZE(HierarchyName)); + strlcpy(Name, HierarchyName, ARRAY_SIZE(Name)); strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, AnimName, ARRAY_SIZE(Name)); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp index 790abf043a..2a76881dd3 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hrawanim.cpp @@ -211,7 +211,7 @@ int HRawAnimClass::Load_W3D(ChunkLoadClass & cload) pre30 = true; } - strcpy(Name,aheader.HierarchyName); + strlcpy(Name, aheader.HierarchyName, ARRAY_SIZE(Name)); strlcat(Name, ".", ARRAY_SIZE(Name)); strlcat(Name, aheader.Name, ARRAY_SIZE(Name)); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/nullrobj.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/nullrobj.cpp index 8fbc5e9e97..248e2f3313 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/nullrobj.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/nullrobj.cpp @@ -45,16 +45,18 @@ NullLoaderClass _NullLoader; Null3DObjClass::Null3DObjClass(const char * name) { - strcpy(Name, name); + strlcpy(Name, name, ARRAY_SIZE(Name)); } Null3DObjClass::Null3DObjClass(const Null3DObjClass & src) { + static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(src.Name), "Name array size mismatch"); strcpy(Name, src.Name); } Null3DObjClass & Null3DObjClass::operator = (const Null3DObjClass & that) { + static_assert(ARRAY_SIZE(Name) >= ARRAY_SIZE(that.Name), "Name array size mismatch"); strcpy(Name, that.Name); RenderObjClass::operator = (that); return *this; diff --git a/GeneralsMD/Code/Tools/GUIEdit/Include/LayoutScheme.h b/GeneralsMD/Code/Tools/GUIEdit/Include/LayoutScheme.h index dbbe51d888..747c588de0 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Include/LayoutScheme.h +++ b/GeneralsMD/Code/Tools/GUIEdit/Include/LayoutScheme.h @@ -124,7 +124,7 @@ class LayoutScheme // INLINING /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// inline char *LayoutScheme::getSchemeFilename( void ) { return m_schemeFilename; } -inline void LayoutScheme::setSchemeFilename( char *filename ) { strcpy( m_schemeFilename, filename ); } +inline void LayoutScheme::setSchemeFilename( char *filename ) { strlcpy(m_schemeFilename, filename, ARRAY_SIZE(m_schemeFilename)); } inline Color LayoutScheme::getEnabledTextColor( void ) { return m_enabledText.color; } inline Color LayoutScheme::getEnabledTextBorderColor( void ) { return m_enabledText.borderColor; } inline Color LayoutScheme::getDisabledTextColor( void ) { return m_disabledText.color; } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp index 3c842f751d..77822a8dda 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEdit.cpp @@ -251,14 +251,14 @@ void GUIEdit::setSaveFile( const char *fullPathAndFilename ) const char *ptr; // copy over the full path and filename - strcpy( m_savePathAndFilename, fullPathAndFilename ); + strlcpy(m_savePathAndFilename, fullPathAndFilename, ARRAY_SIZE(m_saveFilename)); // // copy everything after the last '\' from the full path, this will // be just the filename with extension // ptr = strrchr( fullPathAndFilename, '\\' ) + 1; - strcpy( m_saveFilename, ptr ); + strlcpy(m_saveFilename, ptr, ARRAY_SIZE(m_saveFilename)); } @@ -3539,7 +3539,6 @@ void GUIEdit::stripNameDecorations( GameWindow *root ) if( !instData->m_decoratedNameString.isEmpty() ) { - char nameOnly[ MAX_WINDOW_NAME_LEN ]; const char *c; // skip past the "filename.wnd:" to the name only @@ -3550,11 +3549,8 @@ void GUIEdit::stripNameDecorations( GameWindow *root ) // skip beyong the scope resolution colon c++; - // copy the name - strcpy( nameOnly, c ); - // put the name only in the decoration field - instData->m_decoratedNameString = nameOnly; + instData->m_decoratedNameString = c; } diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEditWindowManager.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEditWindowManager.cpp index dbed4df9f2..efc03f6691 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEditWindowManager.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/GUIEditWindowManager.cpp @@ -501,7 +501,7 @@ void GUIEditWindowManager::incrementName( GameWindow *window ) // this I will botch it (cuz I'm currently not sure // how to test it) char name[MAX_WINDOW_NAME_LEN]; - strcpy(name, instData->m_decoratedNameString.str()); + strlcpy(name, instData->m_decoratedNameString.str(), ARRAY_SIZE(name)); Int len = strlen( name ); char numberBuffer[ MAX_WINDOW_NAME_LEN ]; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp index 2db5faf7b9..9f7097cbec 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BlendMaterial.cpp @@ -191,15 +191,15 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare } // set the name in the tree view to that of the entry - strcpy( buffer, terrain->getName().str() ); + strlcpy(buffer, terrain->getName().str(), ARRAY_SIZE(buffer)); doAdd = TRUE; } else if (terrainNdx==-1) { - strcpy(buffer, pPath); + strlcpy(buffer, pPath, ARRAY_SIZE(buffer)); doAdd = true; } else if (WorldHeightMapEdit::getTexClassIsBlendEdge(terrainNdx)) { parent = findOrAdd( parent, "**EVAL**" ); - strcpy(buffer, pPath); + strlcpy(buffer, pPath, ARRAY_SIZE(buffer)); doAdd = true; } @@ -207,9 +207,6 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare // Int availableTiles = 4 * tilesPerRow * tilesPerRow; // Int percent = (WorldHeightMapEdit::getTexClassNumTiles(terrainNdx)*100 + availableTiles/2) / availableTiles; - char label[_MAX_PATH]; - snprintf(label, ARRAY_SIZE(label), "%s", buffer); - if( doAdd ) { @@ -220,8 +217,8 @@ void BlendMaterial::addTerrain(const char *pPath, Int terrainNdx, HTREEITEM pare ins.hInsertAfter = TVI_LAST; ins.item.mask = TVIF_PARAM|TVIF_TEXT; ins.item.lParam = terrainNdx; - ins.item.pszText = label; - ins.item.cchTextMax = strlen(label)+2; + ins.item.pszText = buffer; + ins.item.cchTextMax = strlen(buffer)+2; m_terrainTreeView.InsertItem(&ins); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp index 0fdd34cb72..27a597699a 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BuildList.cpp @@ -737,10 +737,10 @@ void BuildList::OnExport() static FILE *theLogFile = NULL; Bool open = false; try { - char dirbuf[ _MAX_PATH ]; - ::GetModuleFileName( NULL, dirbuf, sizeof( dirbuf ) ); - char *pEnd = dirbuf + strlen( dirbuf ); - while( pEnd != dirbuf ) + char buffer[ _MAX_PATH ]; + ::GetModuleFileName( NULL, buffer, sizeof( buffer ) ); + char *pEnd = buffer + strlen( buffer ); + while( pEnd != buffer ) { if( *pEnd == '\\' ) { @@ -750,17 +750,14 @@ void BuildList::OnExport() pEnd--; } - char curbuf[ _MAX_PATH ]; - - strcpy(curbuf, dirbuf); SidesInfo *pSide = TheSidesList->getSideInfo(m_curSide); Dict *d = TheSidesList->getSideInfo(m_curSide)->getDict(); AsciiString name = d->getAsciiString(TheKey_playerName); - strlcat(curbuf, name.str(), ARRAY_SIZE(curbuf)); - strlcat(curbuf, "_BuildList", ARRAY_SIZE(curbuf)); - strlcat(curbuf, ".ini", ARRAY_SIZE(curbuf)); + strlcat(buffer, name.str(), ARRAY_SIZE(buffer)); + strlcat(buffer, "_BuildList", ARRAY_SIZE(buffer)); + strlcat(buffer, ".ini", ARRAY_SIZE(buffer)); - theLogFile = fopen(curbuf, "w"); + theLogFile = fopen(buffer, "w"); if (theLogFile == NULL) throw; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp index 25af1e3b6e..4612838395 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/EditObjectParameter.cpp @@ -100,7 +100,6 @@ BOOL EditObjectParameter::OnInitDialog() //------------------------------------------------------------------------------------------------- void EditObjectParameter::addObject( const ThingTemplate *thingTemplate ) { - char buffer[ _MAX_PATH ]; HTREEITEM parent = TVI_ROOT; const char *leafName; // @@ -121,8 +120,7 @@ void EditObjectParameter::addObject( const ThingTemplate *thingTemplate ) // first sort by Side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH(!side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp index b4fcc6e734..c49e0a24b6 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/FenceOptions.cpp @@ -236,7 +236,6 @@ HTREEITEM FenceOptions::findOrAdd(HTREEITEM parent, const char *pLabel) void FenceOptions::addObject( MapObject *mapObject, const char *pPath, const char *name, Int terrainNdx, HTREEITEM parent ) { - char buffer[ _MAX_PATH ]; const char *leafName = NULL; // sanity @@ -262,8 +261,7 @@ void FenceOptions::addObject( MapObject *mapObject, const char *pPath, const cha // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp index 6e1e94fb7e..37394fdde9 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/MeshMoldOptions.cpp @@ -80,23 +80,11 @@ BOOL MeshMoldOptions::OnInitDialog() m_moldTreeView.ShowWindow(SW_SHOW); { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; Int i; - strcpy(dirBuf, ".\\data\\Editor\\Molds"); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.w3d", ARRAY_SIZE(findBuf)); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.w3d"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory(AsciiString(".\\data\\Editor\\Molds\\"), AsciiString("*.w3d"), filenameList, FALSE); if (filenameList.size() > 0) { HTREEITEM child = NULL; @@ -104,9 +92,9 @@ BOOL MeshMoldOptions::OnInitDialog() do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; - strcpy(fileBuf, filename.str()); + strlcpy(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); for (i=strlen(fileBuf)-1; i>0; i--) { if (fileBuf[i] == '.') { // strip off .w3d file extension. diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp index f7e5b7e471..26bdf2a8f6 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp @@ -277,29 +277,17 @@ BOOL ObjectOptions::OnInitDialog() #endif #ifdef LOAD_TEST_ASSETS { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; Int i; - strcpy(dirBuf, TEST_W3D_DIR_PATH); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\' && dirBuf[len-1] != '/') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - strlcat(findBuf, "*.*", ARRAY_SIZE(findBuf)); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(dirBuf), AsciiString("*.w3d"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory(TEST_W3D_DIR_PATH, "*.w3d", filenameList, FALSE); if (filenameList.size() > 0) { FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - len = filename.getLength(); + Int len = filename.getLength(); if (len<5) continue; // only do .w3d files @@ -309,9 +297,9 @@ BOOL ObjectOptions::OnInitDialog() filename.nextToken(&token, "\\/"); } - strcpy(fileBuf, TEST_STRING); - strlcat(fileBuf, "/", ARRAY_SIZE(findBuf)); - strlcat(fileBuf, token.str(), ARRAY_SIZE(findBuf)); + strlcpy(fileBuf, TEST_STRING, ARRAY_SIZE(fileBuf)); + strlcat(fileBuf, "/", ARRAY_SIZE(fileBuf)); + strlcat(fileBuf, token.str(), ARRAY_SIZE(fileBuf)); for (i=strlen(fileBuf)-1; i>0; i--) { if (fileBuf[i] == '.') { // strip off .w3d file extension. @@ -480,8 +468,7 @@ void ObjectOptions::addObject( MapObject *mapObject, const char *pPath, // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str() ); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp index 754dd298bb..fb9e234446 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/PickUnitDialog.cpp @@ -265,7 +265,7 @@ BOOL PickUnitDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) m_objectTreeView.GetItem(&item); if (item.lParam >= 0) { m_currentObjectIndex = item.lParam; - strcpy(m_currentObjectName, buffer); + strlcpy(m_currentObjectName, buffer, ARRAY_SIZE(m_currentObjectName)); } else if (m_objectTreeView.ItemHasChildren(item.hItem)) { strcpy(m_currentObjectName, ""); m_currentObjectIndex = -1; @@ -307,8 +307,7 @@ void PickUnitDialog::addObject( MapObject *mapObject, const char *pPath, Int ind // first sort by side, either create or find the tree item with matching side name AsciiString side = thingTemplate->getDefaultOwningSide(); DEBUG_ASSERTCRASH( !side.isEmpty(), ("NULL default side in template") ); - strcpy( buffer, side.str() ); - parent = findOrAdd( parent, buffer ); + parent = findOrAdd( parent, side.str()); // next tier uses the editor sorting that design can specify in the INI EditorSortingType i = ES_FIRST; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/RoadOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/RoadOptions.cpp index 861182155c..19bbba7771 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/RoadOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/RoadOptions.cpp @@ -19,7 +19,6 @@ // RoadOptions.cpp : implementation file // - #include "StdAfx.h" #include "resource.h" #include "Lib/BaseType.h" @@ -246,10 +245,11 @@ BOOL RoadOptions::OnInitDialog() char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; + static_assert(ARRAY_SIZE(ROAD_DIRECTORY) <= ARRAY_SIZE(dirBuf), "Buffer size too small"); strcpy(dirBuf, ROAD_DIRECTORY); int len = strlen(dirBuf); - strcpy(findBuf, dirBuf); + strlcpy(findBuf, dirBuf, ARRAY_SIZE(dirBuf)); FilenameList filenameList; TheFileSystem->getFileListInDirectory(AsciiString(findBuf), AsciiString("*.tga"), filenameList, FALSE); @@ -273,6 +273,7 @@ BOOL RoadOptions::OnInitDialog() ++it; continue; } + static_assert(ARRAY_SIZE(TEST_STRING) <= ARRAY_SIZE(fileBuf), "Buffer size too small"); strcpy(fileBuf, TEST_STRING); strlcat(fileBuf, "\\", ARRAY_SIZE(fileBuf)); strlcat(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); @@ -387,7 +388,7 @@ void RoadOptions::addRoad(char *pPath, Int terrainNdx, HTREEITEM parent) parent = findOrAdd( parent, "Roads" ); // set the name to place as the name of the road entry in INI - strcpy( buffer, road->getName().str() ); + strlcpy(buffer, road->getName().str(), ARRAY_SIZE(buffer)); // do the add doAdd = TRUE; @@ -397,7 +398,7 @@ void RoadOptions::addRoad(char *pPath, Int terrainNdx, HTREEITEM parent) #ifdef LOAD_TEST_ASSETS if (!doAdd && !strncmp(TEST_STRING, pPath, strlen(TEST_STRING))) { parent = findOrAdd(parent, TEST_STRING); - strcpy(buffer, pPath + strlen(TEST_STRING) + 1); + strlcpy(buffer, pPath + strlen(TEST_STRING) + 1, ARRAY_SIZE(buffer)); doAdd = true; } #endif diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp index 5867d6588a..cf5c6d77a8 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/SelectMacrotexture.cpp @@ -73,21 +73,10 @@ BOOL SelectMacrotexture::OnInitDialog() m_textureTreeView.ShowWindow(SW_SHOW); { - char dirBuf[_MAX_PATH]; - char findBuf[_MAX_PATH]; char fileBuf[_MAX_PATH]; - strcpy(dirBuf, "..\\TestArt"); - int len = strlen(dirBuf); - - if (len > 0 && dirBuf[len - 1] != '\\') { - dirBuf[len++] = '\\'; - dirBuf[len] = 0; - } - strcpy(findBuf, dirBuf); - FilenameList filenameList; - TheFileSystem->getFileListInDirectory(AsciiString(findBuf), AsciiString("*.tga"), filenameList, FALSE); + TheFileSystem->getFileListInDirectory("..\\TestArt\\", "*.tga", filenameList, FALSE); if (filenameList.size() > 0) { TVINSERTSTRUCT ins; @@ -95,9 +84,9 @@ BOOL SelectMacrotexture::OnInitDialog() FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - len = filename.getLength(); + int len = filename.getLength(); if (len<5) continue; - strcpy(fileBuf, filename.str()); + strlcpy(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); ::memset(&ins, 0, sizeof(ins)); ins.hParent = TVI_ROOT; ins.hInsertAfter = TVI_SORT; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp index 6d356be196..1d2c46b312 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainMaterial.cpp @@ -302,7 +302,7 @@ void TerrainMaterial::addTerrain(char *pPath, Int terrainNdx, HTREEITEM parent) } // set the name in the tree view to that of the entry - strcpy( buffer, terrain->getName().str() ); + strlcpy(buffer, terrain->getName().str(), ARRAY_SIZE(buffer)); doAdd = TRUE; } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp index 17afe7ba5e..ad41eebdd3 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/TerrainModal.cpp @@ -172,7 +172,7 @@ void TerrainModal::addTerrain(char *pPath, Int terrainNdx, HTREEITEM parent) } - strcpy( buffer, terrain->getName().str() ); + strlcpy(buffer, terrain->getName().str(), ARRAY_SIZE(buffer)); doAdd = TRUE; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 972c676027..59c6348146 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -434,7 +434,6 @@ void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - //strcpy(fileBuf, dirBuf); strlcpy(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); loadBitmap(fileBuf, filename.str()); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp index 2a81f78d5c..90449c2bfd 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilder.cpp @@ -125,7 +125,7 @@ char const * WBGameFileClass::Set_Name( char const *filename ) } if (TheFileSystem->doesFileExist(filename)) { - strcpy( m_filePath, filename ); + strlcpy(m_filePath, filename, ARRAY_SIZE(m_filePath)); m_fileExists = true; } return m_filename; @@ -365,7 +365,7 @@ BOOL CWorldBuilderApp::InitInstance() #if 1 // srj sez: put INI into our user data folder, not the ap dir free((void*)m_pszProfileName); - strcpy(buf, TheGlobalData->getPath_UserData().str()); + strlcpy(buf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(buf)); strlcat(buf, "WorldBuilder.ini", ARRAY_SIZE(buf)); #else strlcat(buf, "//", ARRAY_SIZE(buf)); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp index 52bed9d22c..a9859d55f9 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp @@ -436,8 +436,9 @@ AsciiString ConvertToNonGCName(AsciiString name, Bool checkTemplate=true) { char oldName[256]; char newName[256]; - strcpy(oldName, name.str()); - strcpy(newName, oldName+strlen("GC_")); + strlcpy(oldName, name.str(), ARRAY_SIZE(oldName)); + static_assert(ARRAY_SIZE(oldName) >= ARRAY_SIZE("GC_"), "Buffer too small"); + strlcpy(newName, oldName+strlen("GC_"), ARRAY_SIZE(newName)); AsciiString swapName; swapName.set(newName); if (checkTemplate) @@ -455,8 +456,9 @@ AsciiString ConvertName(AsciiString name) { char oldName[256]; char newName[256]; - strcpy(oldName, name.str()); - strcpy(newName, "GLA"); + strlcpy(oldName, name.str(), ARRAY_SIZE(oldName)); + strlcpy(newName, "GLA", ARRAY_SIZE(newName)); + static_assert(ARRAY_SIZE(oldName) >= ARRAY_SIZE("Fundamentalist"), "Buffer too small"); strlcat(newName, oldName+strlen("Fundamentalist"), ARRAY_SIZE(newName)); AsciiString swapName; swapName.set(newName); @@ -471,8 +473,9 @@ AsciiString ConvertFaction(AsciiString name) { char oldName[256]; char newName[256]; - strcpy(oldName, name.str()); + strlcpy(oldName, name.str(), ARRAY_SIZE(oldName)); strcpy(newName, "FactionGLA"); + static_assert(ARRAY_SIZE(oldName) >= ARRAY_SIZE("FactionFundamentalist"), "Buffer too small"); strlcat(newName, oldName+strlen("FactionFundamentalist"), ARRAY_SIZE(newName)); AsciiString swapName; swapName.set(newName); @@ -2175,7 +2178,7 @@ void CWorldBuilderDoc::OnDumpDocToText(void) char curbuf[ _MAX_PATH ]; - strcpy(curbuf, dirbuf); + strlcpy(curbuf, dirbuf, ARRAY_SIZE(curbuf)); strlcat(curbuf, m_strTitle, ARRAY_SIZE(curbuf)); strlcat(curbuf, ".txt", ARRAY_SIZE(curbuf)); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp index b47b83f46f..a0d7487fbe 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp @@ -266,7 +266,7 @@ void MapObjectProps::_TeamToDict(void) static char buf[1024]; owner->GetWindowText(buf, sizeof(buf)-2); if (strcmp(buf, NEUTRAL_TEAM_UI_STR)==0) - strcpy(buf, NEUTRAL_TEAM_INTERNAL_STR); + strlcpy(buf, NEUTRAL_TEAM_INTERNAL_STR, ARRAY_SIZE(buf)); CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc(); if ( pDoc ) diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp index 1c8d56fdf5..d9125debeb 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/playerlistdlg.cpp @@ -87,7 +87,7 @@ static void ensureValidPlayerName(Dict *d) { // ensure there are no illegal chars in it. (in particular, no spaces!) char buf[1024]; - strcpy(buf, d->getAsciiString(TheKey_playerName).str()); + strlcpy(buf, d->getAsciiString(TheKey_playerName).str(), ARRAY_SIZE(buf)); for (char* p = buf; *p; ++p) if (!islegalplayernamechar(*p)) *p = '_'; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp index 2cfa7e5fcd..b499c5be1e 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp @@ -1196,7 +1196,7 @@ void WbView3d::invalBuildListItemInView(BuildListInfo *pBuildToInval) Shadow::ShadowTypeInfo shadowInfo; shadowInfo.allowUpdates=FALSE; //shadow image will never update shadowInfo.allowWorldAlign=TRUE; //shadow image will wrap around world objects - strcpy(shadowInfo.m_ShadowName,tTemplate->getShadowTextureName().str()); + strlcpy(shadowInfo.m_ShadowName, tTemplate->getShadowTextureName().str(), ARRAY_SIZE(shadowInfo.m_ShadowName)); DEBUG_ASSERTCRASH(shadowInfo.m_ShadowName[0] != '\0', ("this should be validated in ThingTemplate now")); shadowInfo.m_type=(ShadowType)tTemplate->getShadowType(); shadowInfo.m_sizeX=tTemplate->getShadowSizeX(); @@ -1313,7 +1313,7 @@ AsciiString WbView3d::getModelNameAndScale(MapObject *pMapObj, Real *scale, Body if (strncmp(TEST_STRING, pMapObj->getName().str(), strlen(TEST_STRING)) == 0) { /* Handle test art models here */ - strcpy(buffer, pMapObj->getName().str()); + strlcpy(buffer, pMapObj->getName().str(), ARRAY_SIZE(buffer)); Int i; for (i=0; buffer[i]; i++) { @@ -1474,7 +1474,7 @@ void WbView3d::invalObjectInView(MapObject *pMapObjIn) shadowInfo.allowWorldAlign=TRUE; //shadow image will wrap around world objects if (tTemplate && tTemplate->getShadowType() != SHADOW_NONE && !(pMapObj->getFlags() & FLAG_DONT_RENDER)) { //add correct type of shadow - strcpy(shadowInfo.m_ShadowName,tTemplate->getShadowTextureName().str()); + strlcpy(shadowInfo.m_ShadowName, tTemplate->getShadowTextureName().str(), ARRAY_SIZE(shadowInfo.m_ShadowName)); DEBUG_ASSERTCRASH(shadowInfo.m_ShadowName[0] != '\0', ("this should be validated in ThingTemplate now")); shadowInfo.m_type=(ShadowType)tTemplate->getShadowType(); shadowInfo.m_sizeX=tTemplate->getShadowSizeX();