Skip to content

Commit

Permalink
Better bounds check from HL25 update.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Sep 15, 2024
1 parent f1c430a commit c30b4a6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
8 changes: 8 additions & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,14 @@ void ClientCommand( edict_t *pEntity )
strncpy( command, pcmd, sizeof(command) - 1);
command[sizeof(command) - 1] = '\0';

// First parse the name and remove any %'s
for( char *pApersand = command; *pApersand; pApersand++ )
{
// Replace it with a space
if( *pApersand == '%' )
*pApersand = ' ';
}

// tell the user they entered an unknown command
ClientPrint( &pEntity->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Unknown command: %s\n", command ) );
}
Expand Down
2 changes: 1 addition & 1 deletion dlls/maprules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void CGamePlayerEquip::KeyValue( KeyValueData *pkvd )
{
char tmp[128];

UTIL_StripToken( pkvd->szKeyName, tmp );
UTIL_StripToken( pkvd->szKeyName, tmp, sizeof( tmp ));

m_weaponNames[i] = ALLOC_STRING( tmp );
m_weaponCount[i] = atoi( pkvd->szValue );
Expand Down
2 changes: 1 addition & 1 deletion dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void CMultiManager::KeyValue( KeyValueData *pkvd )
{
char tmp[128];

UTIL_StripToken( pkvd->szKeyName, tmp );
UTIL_StripToken( pkvd->szKeyName, tmp, sizeof( tmp ));
m_iTargetName[m_cTargets] = ALLOC_STRING( tmp );
m_flTargetDelay[m_cTargets] = atof( pkvd->szValue );
m_cTargets++;
Expand Down
12 changes: 7 additions & 5 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,8 @@ void UTIL_StringToVector( float *pVector, const char *pString )
char *pstr, *pfront, tempString[128];
int j;

strcpy( tempString, pString );
strncpy( tempString, pString, sizeof( tempString ));
tempString[sizeof( tempString ) - 1] = '\0';
pstr = pfront = tempString;

for( j = 0; j < 3; j++ ) // lifted from pr_edict.c
Expand Down Expand Up @@ -1355,7 +1356,8 @@ void UTIL_StringToIntArray( int *pVector, int count, const char *pString )
char *pstr, *pfront, tempString[128];
int j;

strcpy( tempString, pString );
strncpy( tempString, pString, sizeof( tempString ));
tempString[sizeof( tempString ) - 1] = '\0';
pstr = pfront = tempString;

for( j = 0; j < count; j++ ) // lifted from pr_edict.c
Expand Down Expand Up @@ -1560,11 +1562,11 @@ float UTIL_DotPoints( const Vector &vecSrc, const Vector &vecCheck, const Vector
//=========================================================
// UTIL_StripToken - for redundant keynames
//=========================================================
void UTIL_StripToken( const char *pKey, char *pDest )
void UTIL_StripToken( const char *pKey, char *pDest, int nLen )
{
int i = 0;

while( pKey[i] && pKey[i] != '#' )
while( i < nLen - 1 && pKey[i] && pKey[i] != '#' )
{
pDest[i] = pKey[i];
i++;
Expand Down Expand Up @@ -2136,7 +2138,7 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou
{
fieldNumber = ( i + startField ) % fieldCount;
pTest = &pFields[fieldNumber];
if( !stricmp( pTest->fieldName, pName ) )
if( pTest->fieldName && !stricmp( pTest->fieldName, pName ) )
{
if( !m_global || !(pTest->flags & FTYPEDESC_GLOBAL ) )
{
Expand Down
2 changes: 1 addition & 1 deletion dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ extern void UTIL_LogPrintf( const char *fmt, ... );
// Sorta like FInViewCone, but for nonmonsters.
extern float UTIL_DotPoints ( const Vector &vecSrc, const Vector &vecCheck, const Vector &vecDir );

extern void UTIL_StripToken( const char *pKey, char *pDest );// for redundant keynames
extern void UTIL_StripToken( const char *pKey, char *pDest, int nLen );// for redundant keynames

// Misc functions
extern void SetMovedir(entvars_t* pev);
Expand Down

0 comments on commit c30b4a6

Please sign in to comment.