mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-19 14:43:47 +00:00
Use strncpy instead of strcpy because again, buffer overflows
This commit is contained in:
parent
7769da9434
commit
79c34c68db
92 changed files with 298 additions and 279 deletions
|
|
@ -218,7 +218,7 @@ bool GuiFormCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
|
|||
S32 strlen = dStrlen((const char*)mCaption);
|
||||
for(S32 i=strlen; i>=0; --i)
|
||||
{
|
||||
dStrcpy(buf, "");
|
||||
dStrcpy(buf, "", i);
|
||||
dStrcat(buf, (const char*)mCaption, i);
|
||||
dStrcat(buf, "...", i);
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ bool guiAnimBitmapCtrl::ptSetFrameRanges(void *object, const char *index, const
|
|||
return true;
|
||||
}
|
||||
char* tokCopy = new char[dStrlen(data) + 1];
|
||||
dStrcpy(tokCopy, data);
|
||||
dStrcpy(tokCopy, data, dStrlen(data) + 1);
|
||||
|
||||
char* currTok = dStrtok(tokCopy, " \t");
|
||||
while (currTok != NULL)
|
||||
|
|
@ -291,4 +291,4 @@ void guiAnimBitmapCtrl::onRender(Point2I offset, const RectI &updateRect)
|
|||
}
|
||||
|
||||
renderChildControls(offset, updateRect);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ void GuiFileTreeCtrl::recurseInsert( Item* parent, StringTableEntry path )
|
|||
|
||||
char szPathCopy [ 1024 ];
|
||||
dMemset( szPathCopy, 0, 1024 );
|
||||
dStrcpy( szPathCopy, path );
|
||||
dStrcpy( szPathCopy, path, 1024 );
|
||||
|
||||
// Jump over the first character if it's a root /
|
||||
char *curPos = szPathCopy;
|
||||
|
|
|
|||
|
|
@ -566,13 +566,14 @@ void GuiPopUpMenuCtrl::setBitmap( const char *name )
|
|||
{
|
||||
char buffer[1024];
|
||||
char *p;
|
||||
dStrcpy(buffer, name);
|
||||
dStrcpy(buffer, name, 1024);
|
||||
p = buffer + dStrlen(buffer);
|
||||
S32 pLen = 1024 - dStrlen(buffer);
|
||||
|
||||
dStrcpy(p, "_n");
|
||||
dStrcpy(p, "_n", pLen);
|
||||
mTextureNormal = GFXTexHandle( (StringTableEntry)buffer, &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) );
|
||||
|
||||
dStrcpy(p, "_d");
|
||||
dStrcpy(p, "_d", pLen);
|
||||
mTextureDepressed = GFXTexHandle( (StringTableEntry)buffer, &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__) );
|
||||
if ( !mTextureDepressed )
|
||||
mTextureDepressed = mTextureNormal;
|
||||
|
|
@ -637,7 +638,7 @@ void GuiPopUpMenuCtrl::addEntry( const char *buf, S32 id, U32 scheme )
|
|||
mIdMax = id;
|
||||
|
||||
Entry e;
|
||||
dStrcpy( e.buf, buf );
|
||||
dStrcpy( e.buf, buf, 256 );
|
||||
e.id = id;
|
||||
e.scheme = scheme;
|
||||
|
||||
|
|
|
|||
|
|
@ -771,13 +771,14 @@ void GuiPopUpMenuCtrlEx::setBitmap(const char *name)
|
|||
{
|
||||
char buffer[1024];
|
||||
char *p;
|
||||
dStrcpy(buffer, name);
|
||||
dStrcpy(buffer, name, 1024);
|
||||
p = buffer + dStrlen(buffer);
|
||||
S32 pLen = 1024 - dStrlen(buffer);
|
||||
|
||||
dStrcpy(p, "_n");
|
||||
dStrcpy(p, "_n", pLen);
|
||||
mTextureNormal = GFXTexHandle( (StringTableEntry)buffer, &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__) );
|
||||
|
||||
dStrcpy(p, "_d");
|
||||
dStrcpy(p, "_d", pLen);
|
||||
mTextureDepressed = GFXTexHandle( (StringTableEntry)buffer, &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__) );
|
||||
if ( !mTextureDepressed )
|
||||
mTextureDepressed = mTextureNormal;
|
||||
|
|
@ -840,7 +841,7 @@ void GuiPopUpMenuCtrlEx::addEntry(const char *buf, S32 id, U32 scheme)
|
|||
mIdMax = id;
|
||||
|
||||
Entry e;
|
||||
dStrcpy( e.buf, buf );
|
||||
dStrcpy( e.buf, buf, 256 );
|
||||
e.id = id;
|
||||
e.scheme = scheme;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ GuiTabPageCtrl::GuiTabPageCtrl(void)
|
|||
{
|
||||
setExtent(Point2I(100, 200));
|
||||
mFitBook = false;
|
||||
dStrcpy(mText,(UTF8*)"TabPage");
|
||||
dStrcpy(mText,(UTF8*)"TabPage", MAX_STRING_LENGTH);
|
||||
mActive = true;
|
||||
mIsContainer = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4754,15 +4754,15 @@ StringTableEntry GuiTreeViewCtrl::getTextToRoot( S32 itemId, const char * delimi
|
|||
dMemset( bufferOne, 0, sizeof(bufferOne) );
|
||||
dMemset( bufferTwo, 0, sizeof(bufferTwo) );
|
||||
|
||||
dStrcpy( bufferOne, item->getText() );
|
||||
dStrcpy( bufferOne, item->getText(), 1024 );
|
||||
|
||||
Item *prevNode = item->mParent;
|
||||
while ( prevNode )
|
||||
{
|
||||
dMemset( bufferNodeText, 0, sizeof(bufferNodeText) );
|
||||
dStrcpy( bufferNodeText, prevNode->getText() );
|
||||
dStrcpy( bufferNodeText, prevNode->getText(), 128 );
|
||||
dSprintf( bufferTwo, 1024, "%s%s%s",bufferNodeText, delimiter, bufferOne );
|
||||
dStrcpy( bufferOne, bufferTwo );
|
||||
dStrcpy( bufferOne, bufferTwo, 1024 );
|
||||
dMemset( bufferTwo, 0, sizeof(bufferTwo) );
|
||||
prevNode = prevNode->mParent;
|
||||
}
|
||||
|
|
@ -5570,4 +5570,4 @@ DefineEngineMethod(GuiTreeViewCtrl, getItemAtPosition, S32, (Point2I position),
|
|||
"@return The id of the item under the position.")
|
||||
{
|
||||
return object->getItemAtPosition(position);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2570,7 +2570,7 @@ DefineEngineMethod( GuiControl, findHitControls, const char*, ( S32 x, S32 y, S3
|
|||
return "";
|
||||
|
||||
char* buffer = Con::getReturnBuffer( s.size() );
|
||||
dStrcpy( buffer, s.c_str() );
|
||||
dStrcpy( buffer, s.c_str(), s.size() );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ bool DbgFileView::findMouseOverVariable()
|
|||
{
|
||||
S32 stringPosition = pt.x - gFileXOffset;
|
||||
char tempBuf[256], *varNamePtr = &tempBuf[1];
|
||||
dStrcpy(tempBuf, mFileView[cell.y].text);
|
||||
dStrcpy(tempBuf, mFileView[cell.y].text, 256);
|
||||
|
||||
//find the current mouse over char
|
||||
S32 charNum = findMouseOverChar(mFileView[cell.y].text, stringPosition);
|
||||
|
|
@ -526,7 +526,7 @@ void DbgFileView::onPreRender()
|
|||
{
|
||||
setUpdate();
|
||||
char oldVar[256];
|
||||
dStrcpy(oldVar, mMouseOverVariable);
|
||||
dStrcpy(oldVar, mMouseOverVariable, 256);
|
||||
bool found = findMouseOverVariable();
|
||||
if (found && mPCCurrentLine >= 0)
|
||||
{
|
||||
|
|
@ -685,7 +685,7 @@ void DbgFileView::onRenderCell(Point2I offset, Point2I cell, bool selected, bool
|
|||
{
|
||||
S32 startPos, endPos;
|
||||
char tempBuf[256];
|
||||
dStrcpy(tempBuf, mFileView[cell.y].text);
|
||||
dStrcpy(tempBuf, mFileView[cell.y].text, 256);
|
||||
|
||||
//get the end coord
|
||||
tempBuf[mBlockEnd] = '\0';
|
||||
|
|
|
|||
|
|
@ -2626,7 +2626,7 @@ DefineConsoleMethod( GuiEditCtrl, getSelectionGlobalBounds, const char*, (), , "
|
|||
String str = String::ToString( "%i %i %i %i", bounds.point.x, bounds.point.y, bounds.extent.x, bounds.extent.y );
|
||||
|
||||
char* buffer = Con::getReturnBuffer( str.length() );
|
||||
dStrcpy( buffer, str.c_str() );
|
||||
dStrcpy( buffer, str.c_str(), str.length() );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ void Filter::set(S32 argc, const char *argv[])
|
|||
if (argc == 1)
|
||||
{ // in the form of one string "1.0 1.0 1.0"
|
||||
char list[1024];
|
||||
dStrcpy(list, *argv); // strtok modifies the string so we need to copy it
|
||||
dStrcpy(list, *argv, 1024); // strtok modifies the string so we need to copy it
|
||||
char *value = dStrtok(list, " ");
|
||||
while (value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -500,7 +500,7 @@ void MessageVector::insertLine(const U32 position,
|
|||
|
||||
U32 len = dStrlen(newMessage) + 1;
|
||||
char* copy = new char[len];
|
||||
dStrcpy(copy, newMessage);
|
||||
dStrcpy(copy, newMessage, len);
|
||||
|
||||
mMessageLines.insert(position);
|
||||
mMessageLines[position].message = copy;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue