-
Notifications
You must be signed in to change notification settings - Fork 118
fix: Replace strcpy with strlcpy for robustness #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use assert like in |
||
| } | ||
|
|
||
| /*********************************************************************************************** | ||
|
|
@@ -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)); | ||
| } | ||
|
|
||
| // | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -533,8 +533,8 @@ | |
| // Copy all characters from start to end (excluding 'end') | ||
| // into the w3d_name buffer. Then capitalize the string. | ||
| int num_chars = end - start; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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)); | ||
|
Check warning on line 537 in Core/Libraries/Source/WWVegas/WW3D2/w3d_dep.cpp
|
||
| strupr(w3d_name); | ||
| } | ||
|
|
||
|
|
@@ -565,7 +565,7 @@ | |
| buffer[0] = 0; | ||
| return buffer; | ||
| } | ||
| strcpy(buffer, w3d_name); | ||
| strlcpy(buffer, w3d_name, ARRAY_SIZE(buffer)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same Assert as in sphereobj.cpp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert was not changed |
||
| char *dot = strchr(buffer, '.'); | ||
| if (dot) | ||
| *dot = 0; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,10 +349,10 @@ void PerfGather::reset() | |
| { | ||
| PerfGather::termPerfDump(); | ||
|
|
||
| strcpy(s_buf, fname); | ||
| strlcpy(s_buf, fname, _MAX_PATH); | ||
|
|
||
| char tmp[256]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _MAX_PATH There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely _MAX_PATH |
||
| strcpy(tmp, s_buf); | ||
| strlcpy(tmp, s_buf, ARRAY_SIZE(tmp)); | ||
| strlcat(tmp, ".csv", ARRAY_SIZE(tmp)); | ||
|
|
||
| s_perfStatsFile = fopen(tmp, "w"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This string copy is unnecessary. We can use |
||
| char *p = strrchr( string, '\\' ); | ||
| if( p == NULL ) | ||
| saveGameInfo->mapLabel = TheGlobalData->m_mapName; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.