mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +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
|
|
@ -668,13 +668,13 @@ void BitStream::readString(char buf[256])
|
|||
{
|
||||
S32 offset = readInt(8);
|
||||
HuffmanProcessor::g_huffProcessor.readHuffBuffer(this, stringBuffer + offset);
|
||||
dStrcpy(buf, stringBuffer);
|
||||
dStrcpy(buf, stringBuffer, 256);
|
||||
return;
|
||||
}
|
||||
}
|
||||
HuffmanProcessor::g_huffProcessor.readHuffBuffer(this, buf);
|
||||
if(stringBuffer)
|
||||
dStrcpy(stringBuffer, buf);
|
||||
dStrcpy(stringBuffer, buf, 256);
|
||||
}
|
||||
|
||||
void BitStream::writeString(const char *string, S32 maxLen)
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ StringTableEntry _StringTable::insert(const char* _val, const bool caseSens)
|
|||
*walk = (Node *) mempool.alloc(sizeof(Node));
|
||||
(*walk)->next = 0;
|
||||
(*walk)->val = (char *) mempool.alloc(dStrlen(val) + 1);
|
||||
dStrcpy((*walk)->val, val);
|
||||
dStrcpy((*walk)->val, val, dStrlen(val) + 1);
|
||||
ret = (*walk)->val;
|
||||
itemCount ++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ void FindMatch::setExpression( const char *_expression )
|
|||
delete [] expression;
|
||||
|
||||
expression = new char[dStrlen(_expression) + 1];
|
||||
dStrcpy(expression, _expression);
|
||||
dStrcpy(expression, _expression, dStrlen(_expression) + 1);
|
||||
dStrupr(expression);
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ bool FindMatch::findMatch( const char *str, bool caseSensitive )
|
|||
return false;
|
||||
|
||||
char nstr[512];
|
||||
dStrcpy( nstr,str );
|
||||
dStrcpy( nstr,str,512 );
|
||||
dStrupr(nstr);
|
||||
if ( isMatch( expression, nstr, caseSensitive ) )
|
||||
{
|
||||
|
|
@ -143,7 +143,7 @@ bool FindMatch::isMatchMultipleExprs( const char *exps, const char *str, bool ca
|
|||
S32 len = dStrlen(exps);
|
||||
|
||||
char *e = new char[len+1];
|
||||
dStrcpy(e,exps);
|
||||
dStrcpy(e,exps,len+1);
|
||||
|
||||
// [tom, 12/18/2006] This no longer supports space separated expressions as
|
||||
// they don't work when the paths have spaces in.
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ S32 dStrnatcasecmp(const nat_char* a, const nat_char* b) {
|
|||
char *dStrdup_r(const char *src, const char *fileName, dsize_t lineNumber)
|
||||
{
|
||||
char *buffer = (char *) dMalloc_r(dStrlen(src) + 1, fileName, lineNumber);
|
||||
dStrcpy(buffer, src);
|
||||
dStrcpy(buffer, src, dStrlen(src) + 1);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
#endif // defined(TORQUE_OS_WIN)
|
||||
|
||||
#define DEBUG_CHECK_OVERFLOW 1
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// standard string functions [defined in platformString.cpp]
|
||||
|
|
@ -60,12 +61,16 @@ inline char *dStrcat(char *dst, const char *src)
|
|||
|
||||
inline char *dStrcat(char *dst, const char *src, dsize_t len)
|
||||
{
|
||||
#ifdef DEBUG_CHECK_OVERFLOW
|
||||
if (strlen(src) >= len) {
|
||||
AssertWarn(false, "dStrcat out of range");
|
||||
}
|
||||
#endif
|
||||
return strncat(dst,src,len - 1); //Safety because strncat copies at most len+1 characters
|
||||
}
|
||||
|
||||
inline char *dStrncat(char *dst, const char *src, dsize_t len)
|
||||
{
|
||||
AssertFatal(false, "Use dStrcat with length");
|
||||
return dStrcat(dst, src, len);
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +99,21 @@ inline S32 dStrnicmp(const char *str1, const char *str2, dsize_t len)
|
|||
return strncasecmp( str1, str2, len );
|
||||
}
|
||||
|
||||
/// @deprecated Use strcpy(char *, const char *, dsize_t) instead
|
||||
inline char *dStrcpy(char *dst, const char *src)
|
||||
{
|
||||
AssertFatal(false, "dStrcpy without length is deprecated");
|
||||
return strcpy(dst,src);
|
||||
}
|
||||
|
||||
inline char *dStrcpy(char *dst, const char *src, dsize_t len)
|
||||
{
|
||||
#ifdef DEBUG_CHECK_OVERFLOW
|
||||
if (strlen(src) >= len) {
|
||||
AssertWarn(false, "dStrcpy out of range");
|
||||
}
|
||||
#endif
|
||||
return strncpy(dst,src,len);
|
||||
}
|
||||
|
||||
inline char *dStrncpy(char *dst, const char *src, dsize_t len)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ bool Tokenizer::openFile(const char* pFileName)
|
|||
delete pStream;
|
||||
return false;
|
||||
}
|
||||
dStrcpy(mFileName, pFileName);
|
||||
dStrcpy(mFileName, pFileName, 1024);
|
||||
|
||||
mBufferSize = pStream->getStreamSize();
|
||||
mpBuffer = new char[mBufferSize];
|
||||
|
|
@ -99,7 +99,7 @@ void Tokenizer::setBuffer(const char* buffer, U32 bufferSize)
|
|||
|
||||
mBufferSize = bufferSize;
|
||||
mpBuffer = new char[mBufferSize + 1];
|
||||
dStrcpy(mpBuffer, buffer);
|
||||
dStrcpy(mpBuffer, buffer, mBufferSize + 1);
|
||||
|
||||
reset();
|
||||
|
||||
|
|
@ -634,4 +634,4 @@ bool Tokenizer::endOfFile()
|
|||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ void CentralDir::setFileComment(const char *comment)
|
|||
{
|
||||
SAFE_DELETE_ARRAY(mFileComment);
|
||||
mFileComment = new char [dStrlen(comment)+1];
|
||||
dStrcpy(mFileComment, comment);
|
||||
dStrcpy(mFileComment, comment, dStrlen(comment)+1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue