Skip to content

Commit a11e0e0

Browse files
author
Bart Roossien
committed
fix: Replace strcpy with strlcpy
1 parent b838c65 commit a11e0e0

File tree

65 files changed

+202
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+202
-221
lines changed

Core/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void DebugInit(int flags)
387387
pEnd--;
388388
}
389389

390-
strcpy(theLogFileNamePrev, dirbuf);
390+
strlcpy(theLogFileNamePrev, dirbuf, ARRAY_SIZE(theLogFileNamePrev));
391391
strlcat(theLogFileNamePrev, gAppPrefix, ARRAY_SIZE(theLogFileNamePrev));
392392
strlcat(theLogFileNamePrev, DEBUG_FILE_NAME_PREV, ARRAY_SIZE(theLogFileNamePrev));
393393
if (rts::ClientInstance::getInstanceId() > 1u)
@@ -397,7 +397,7 @@ void DebugInit(int flags)
397397
}
398398
strlcat(theLogFileNamePrev, ".txt", ARRAY_SIZE(theLogFileNamePrev));
399399

400-
strcpy(theLogFileName, dirbuf);
400+
strlcpy(theLogFileName, dirbuf, ARRAY_SIZE(theLogFileNamePrev));
401401
strlcat(theLogFileName, gAppPrefix, ARRAY_SIZE(theLogFileNamePrev));
402402
strlcat(theLogFileName, DEBUG_FILE_NAME, ARRAY_SIZE(theLogFileNamePrev));
403403
if (rts::ClientInstance::getInstanceId() > 1u)
@@ -736,9 +736,9 @@ void ReleaseCrash(const char *reason)
736736
return; // We are shutting down, and TheGlobalData has been freed. jba. [4/15/2003]
737737
}
738738

739-
strcpy(prevbuf, TheGlobalData->getPath_UserData().str());
739+
strlcpy(prevbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(prevbuf));
740740
strlcat(prevbuf, RELEASECRASH_FILE_NAME_PREV, ARRAY_SIZE(prevbuf));
741-
strcpy(curbuf, TheGlobalData->getPath_UserData().str());
741+
strlcpy(curbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(curbuf));
742742
strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf));
743743

744744
remove(prevbuf);
@@ -825,9 +825,9 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
825825
char prevbuf[ _MAX_PATH ];
826826
char curbuf[ _MAX_PATH ];
827827

828-
strcpy(prevbuf, TheGlobalData->getPath_UserData().str());
828+
strlcpy(prevbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(prevbuf));
829829
strlcat(prevbuf, RELEASECRASH_FILE_NAME_PREV, ARRAY_SIZE(prevbuf));
830-
strcpy(curbuf, TheGlobalData->getPath_UserData().str());
830+
strlcpy(curbuf, TheGlobalData->getPath_UserData().str(), ARRAY_SIZE(curbuf));
831831
strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf));
832832

833833
remove(prevbuf);

Core/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ void MemoryPoolFactory::memoryPoolUsageReport( const char* filename, FILE *appen
29752975
if( !appendToFileInstead )
29762976
{
29772977
char tmp[256];
2978-
strcpy(tmp,filename);
2978+
strlcpy(tmp, filename, ARRAY_SIZE(tmp));
29792979
strlcat(tmp, ".csv", ARRAY_SIZE(tmp));
29802980
perfStatsFile = fopen(tmp, "w");
29812981
}

Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect
227227
std::replace(fixedDirectory.begin(), fixedDirectory.end(), '\\', '/');
228228
#endif
229229

230-
strcpy(search, fixedDirectory.c_str());
230+
strlcpy(search, fixedDirectory.c_str(), ARRAY_SIZE(search));
231231

232232
Bool done = FALSE;
233233
std::error_code ec;

Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void Win32LocalFileSystem::getFileListInDirectory(const AsciiString& currentDire
132132
asciisearch = originalDirectory;
133133
asciisearch.concat(currentDirectory);
134134
asciisearch.concat(searchName);
135-
strcpy(search, asciisearch.str());
135+
strlcpy(search, asciisearch.str(), ARRAY_SIZE(search));
136136

137137
Bool done = FALSE;
138138

Core/Libraries/Source/WWVegas/WW3D2/hcanim.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int HCompressedAnimClass::Load_W3D(ChunkLoadClass & cload)
256256

257257
cload.Close_Chunk();
258258

259-
strcpy(Name,aheader.HierarchyName);
259+
strlcpy(Name, aheader.HierarchyName, ARRAY_SIZE(Name));
260260
strlcat(Name, ".", ARRAY_SIZE(Name));
261261
strlcat(Name, aheader.Name, ARRAY_SIZE(Name));
262262

Core/Libraries/Source/WWVegas/WW3D2/hmdldef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int HModelDefClass::Load_W3D(ChunkLoadClass & cload)
151151
*/
152152
strlcpy(ModelName,header.Name,W3D_NAME_LEN);
153153
strlcpy(BasePoseName,header.HierarchyName,W3D_NAME_LEN);
154-
strcpy(Name,ModelName);
154+
strlcpy(Name, ModelName, ARRAY_SIZE(Name));
155155

156156
/*
157157
** Just allocate a node for the number of sub objects we're expecting
@@ -233,7 +233,7 @@ bool HModelDefClass::read_connection(ChunkLoadClass & cload,HmdlNodeDefStruct *
233233
return false;
234234
}
235235

236-
strcpy(node->RenderObjName,ModelName);
236+
strlcpy(node->RenderObjName, ModelName, ARRAY_SIZE(node->RenderObjName));
237237
strlcat(node->RenderObjName, ".", ARRAY_SIZE(node->RenderObjName));
238238
strlcat(node->RenderObjName, con.RenderObjName, ARRAY_SIZE(node->RenderObjName));
239239

Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void RingRenderObjClass::Set_Name(const char * name)
503503
{
504504
WWASSERT(name != NULL);
505505
WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
506-
strcpy(Name,name);
506+
strlcpy(Name, name, ARRAY_SIZE(Name));
507507
}
508508

509509
/***********************************************************************************************
@@ -1206,7 +1206,7 @@ RingPrototypeClass::RingPrototypeClass (void)
12061206
RingPrototypeClass::RingPrototypeClass(RingRenderObjClass *ring)
12071207
{
12081208
::memset (&Definition, 0, sizeof (Definition));
1209-
::strcpy (Definition.Name, ring->Get_Name ());
1209+
strlcpy (Definition.Name, ring->Get_Name(), ARRAY_SIZE(Definition.Name));
12101210

12111211
Definition.AnimDuration = ring->AnimDuration;
12121212
Definition.Attributes = ring->Get_Flags ();
@@ -1237,7 +1237,7 @@ RingPrototypeClass::RingPrototypeClass(RingRenderObjClass *ring)
12371237
filename = name;
12381238
}
12391239

1240-
::strcpy (Definition.TextureName, filename);
1240+
strlcpy(Definition.TextureName, filename, ARRAY_SIZE(Definition.TextureName));
12411241
}
12421242

12431243
//

Core/Libraries/Source/WWVegas/WW3D2/sphereobj.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void SphereRenderObjClass::Set_Name(const char * name)
438438
{
439439
WWASSERT(name != NULL);
440440
WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
441-
strcpy(Name,name);
441+
strlcpy(Name, name, ARRAY_SIZE(Name));
442442
}
443443

444444

@@ -1162,7 +1162,7 @@ SpherePrototypeClass::SpherePrototypeClass (void)
11621162
SpherePrototypeClass::SpherePrototypeClass(SphereRenderObjClass *sphere)
11631163
{
11641164
::memset (&Definition, 0, sizeof (Definition));
1165-
::strcpy (Definition.Name, sphere->Get_Name ());
1165+
strlcpy(Definition.Name, sphere->Get_Name(), ARRAY_SIZE(Definition.Name));
11661166

11671167
Definition.DefaultAlpha = sphere->Get_Default_Alpha ();
11681168
Definition.AnimDuration = sphere->AnimDuration;
@@ -1190,7 +1190,7 @@ SpherePrototypeClass::SpherePrototypeClass(SphereRenderObjClass *sphere)
11901190
filename = name;
11911191
}
11921192

1193-
::strcpy (Definition.TextureName, filename);
1193+
strlcpy(Definition.TextureName, filename, ARRAY_SIZE(Definition.TextureName));
11941194

11951195
}
11961196

Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static const char * Make_W3D_Filename (const char *w3d_name)
565565
buffer[0] = 0;
566566
return buffer;
567567
}
568-
strcpy(buffer, w3d_name);
568+
strlcpy(buffer, w3d_name, ARRAY_SIZE(buffer));
569569
char *dot = strchr(buffer, '.');
570570
if (dot)
571571
*dot = 0;

Core/Libraries/Source/WWVegas/WWDownload/FTP.CPP

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ HRESULT Cftp::FileRecoveryPosition( LPCSTR szLocalFileName, LPCSTR szRegistryRo
17211721
17221722
// Concatenate the registry key together
17231723
1724-
strcpy( regkey, szRegistryRoot );
1724+
strlcpy(regkey, szRegistryRoot, ARRAY_SIZE(regkey));
17251725
if( regkey[ strlen( regkey ) - 1 ] != '\\' )
17261726
{
17271727
strlcat(regkey, "\\Download", ARRAY_SIZE(regkey));

0 commit comments

Comments
 (0)