mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +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
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue