diff --git a/mp/src/game/client/c_baseanimating.cpp b/mp/src/game/client/c_baseanimating.cpp index 78bc38b..86990b9 100644 --- a/mp/src/game/client/c_baseanimating.cpp +++ b/mp/src/game/client/c_baseanimating.cpp @@ -3604,7 +3604,7 @@ bool C_BaseAnimating::DispatchMuzzleEffect( const char *options, bool isFirstPer int weaponType = 0; // Get the first parameter - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); // Find the weapon type if ( token[0] ) @@ -3648,7 +3648,7 @@ bool C_BaseAnimating::DispatchMuzzleEffect( const char *options, bool isFirstPer } // Get the second parameter - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); int attachmentIndex = -1; @@ -3759,7 +3759,7 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int // Get the particle effect name const char *p = options; - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); const char* mtoken = ModifyEventParticles( token ); if ( !mtoken || mtoken[0] == '\0' ) @@ -3767,7 +3767,7 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int Q_strncpy( szParticleEffect, mtoken, sizeof(szParticleEffect) ); // Get the attachment type - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); iAttachType = GetAttachTypeFromString( token ); if ( iAttachType == -1 ) @@ -3777,7 +3777,7 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int } // Get the attachment point index - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if ( token[0] ) { iAttachment = atoi(token); @@ -3981,11 +3981,11 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int const char *p = options; // Bodygroup Name - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); Q_strncpy( szBodygroupName, token, sizeof(szBodygroupName) ); // Get the desired value - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); value = token[0] ? atoi( token ) : 0; int index = FindBodygroupByName( szBodygroupName ); @@ -4022,13 +4022,13 @@ void C_BaseAnimating::FireObsoleteEvent( const Vector& origin, const QAngle& ang const char *p = options; - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); Q_strncpy( effectFunc, token, sizeof(effectFunc) ); - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); iAttachment = token[0] ? atoi(token) : -1; - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); iParam = token[0] ? atoi(token) : 0; if ( iAttachment != -1 && m_Attachments.Count() >= iAttachment ) diff --git a/mp/src/game/client/cdll_util.cpp b/mp/src/game/client/cdll_util.cpp index 4e87753..6ad282b 100644 --- a/mp/src/game/client/cdll_util.cpp +++ b/mp/src/game/client/cdll_util.cpp @@ -727,13 +727,17 @@ CBaseEntity *CEntitySphereQuery::GetCurrentEntity() // Input : token - Returns with a token, or zero length if the token was missing. // str - String to parse. // sep - Character to use as separator. UNDONE: allow multiple separator chars +// tokenLen - Length of token buffer // Output : Returns a pointer to the next token to be parsed. //----------------------------------------------------------------------------- -const char *nexttoken(char *token, const char *str, char sep) +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen) { if ((str == NULL) || (*str == '\0')) { - *token = '\0'; + if(tokenLen) + { + *token = '\0'; + } return(NULL); } @@ -741,11 +745,25 @@ const char *nexttoken(char *token, const char *str, char sep) // Copy everything up to the first separator into the return buffer. // Do not include separators in the return buffer. // - while ((*str != sep) && (*str != '\0')) + while ((*str != sep) && (*str != '\0') && (tokenLen > 1)) { *token++ = *str++; + tokenLen--; + } + + // + // If token is to big for return buffer, skip rest of token. + // + while ((*str != sep) && (*str != '\0')) + { + str++; + } + + if(tokenLen) + { + *token = '\0'; + tokenLen--; } - *token = '\0'; // // Advance the pointer unless we hit the end of the input string. diff --git a/mp/src/game/client/cdll_util.h b/mp/src/game/client/cdll_util.h index 64beb5f..6e17327 100644 --- a/mp/src/game/client/cdll_util.h +++ b/mp/src/game/client/cdll_util.h @@ -89,7 +89,7 @@ void NormalizeAngles( QAngle& angles ); void InterpolateAngles( const QAngle& start, const QAngle& end, QAngle& output, float frac ); void InterpolateVector( float frac, const Vector& src, const Vector& dest, Vector& output ); -const char *nexttoken(char *token, const char *str, char sep); +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen); //----------------------------------------------------------------------------- // Base light indices to avoid index collision diff --git a/mp/src/game/client/hud_closecaption.cpp b/mp/src/game/client/hud_closecaption.cpp index c1a1fa2..44a0552 100644 --- a/mp/src/game/client/hud_closecaption.cpp +++ b/mp/src/game/client/hud_closecaption.cpp @@ -2357,11 +2357,11 @@ bool CHudCloseCaption::AddAsyncWork( const char *tokenstream, bool bIsStream, fl char tokenname[ 512 ]; tokenname[ 0 ] = 0; const char *p = tokenstream; - p = nexttoken( tokenname, p, ' ' ); + p = nexttoken(tokenname, p, ' ' , sizeof(tokenname)); // p points to reset of sentence tokens, build up a unicode string from them... while ( p && Q_strlen( tokenname ) > 0 ) { - p = nexttoken( tokenname, p, ' ' ); + p = nexttoken(tokenname, p, ' ' , sizeof(tokenname)); if ( Q_strlen( tokenname ) == 0 ) break; @@ -2396,7 +2396,7 @@ void CHudCloseCaption::ProcessSentenceCaptionStream( const char *tokenstream ) const char *p = tokenstream; - p = nexttoken( tokenname, p, ' ' ); + p = nexttoken(tokenname, p, ' ' , sizeof(tokenname)); if ( Q_strlen( tokenname ) > 0 ) { diff --git a/mp/src/game/server/baseentity.cpp b/mp/src/game/server/baseentity.cpp index 9bd525a..a1d2a5f 100644 --- a/mp/src/game/server/baseentity.cpp +++ b/mp/src/game/server/baseentity.cpp @@ -4825,7 +4825,7 @@ void CBaseEntity::PrecacheModelComponents( int nModelIndex ) { char token[256]; const char *pOptions = pEvent->pszOptions(); - nexttoken( token, pOptions, ' ' ); + nexttoken(token, pOptions, ' ' , sizeof(token)); if ( token[0] ) { PrecacheParticleSystem( token ); diff --git a/mp/src/game/server/cbase.cpp b/mp/src/game/server/cbase.cpp index d6627b4..15a7d6e 100644 --- a/mp/src/game/server/cbase.cpp +++ b/mp/src/game/server/cbase.cpp @@ -132,7 +132,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the target name. // - const char *psz = nexttoken(szToken, ActionData, ','); + const char *psz = nexttoken(szToken, ActionData, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_iTarget = AllocPooledString(szToken); @@ -141,7 +141,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the input name. // - psz = nexttoken(szToken, psz, ','); + psz = nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_iTargetInput = AllocPooledString(szToken); @@ -154,7 +154,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the parameter override. // - psz = nexttoken(szToken, psz, ','); + psz = nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_iParameter = AllocPooledString(szToken); @@ -163,7 +163,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the delay. // - psz = nexttoken(szToken, psz, ','); + psz = nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_flDelay = atof(szToken); @@ -172,7 +172,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the number of times to fire. // - nexttoken(szToken, psz, ','); + nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_nTimesToFire = atoi(szToken); diff --git a/mp/src/game/server/hl2/npc_BaseZombie.cpp b/mp/src/game/server/hl2/npc_BaseZombie.cpp index e7e5c6f..1ee291e 100644 --- a/mp/src/game/server/hl2/npc_BaseZombie.cpp +++ b/mp/src/game/server/hl2/npc_BaseZombie.cpp @@ -1616,7 +1616,7 @@ void CNPC_BaseZombie::HandleAnimEvent( animevent_t *pEvent ) const char *pString = pEvent->options; char token[128]; - pString = nexttoken( token, pString, ' ' ); + pString = nexttoken(token, pString, ' ' , sizeof(token)); int boneIndex = GetInteractionPartner()->LookupBone( token ); @@ -1626,7 +1626,7 @@ void CNPC_BaseZombie::HandleAnimEvent( animevent_t *pEvent ) return; } - pString = nexttoken( token, pString, ' ' ); + pString = nexttoken(token, pString, ' ' , sizeof(token)); if ( !token ) { diff --git a/mp/src/game/server/mapentities.cpp b/mp/src/game/server/mapentities.cpp index a08ad1e..0ee8220 100644 --- a/mp/src/game/server/mapentities.cpp +++ b/mp/src/game/server/mapentities.cpp @@ -86,7 +86,7 @@ string_t ExtractParentName(string_t parentName) return parentName; char szToken[256]; - nexttoken(szToken, STRING(parentName), ','); + nexttoken(szToken, STRING(parentName), ',', sizeof(szToken)); return AllocPooledString(szToken); } @@ -208,7 +208,7 @@ void SetupParentsForSpawnList( int nEntities, HierarchicalSpawn_t *pSpawnList ) if ( strchr(STRING(pEntity->m_iParent), ',') ) { char szToken[256]; - const char *pAttachmentName = nexttoken(szToken, STRING(pEntity->m_iParent), ','); + const char *pAttachmentName = nexttoken(szToken, STRING(pEntity->m_iParent), ',', sizeof(szToken)); pEntity->m_iParent = AllocPooledString(szToken); CBaseEntity *pParent = gEntList.FindEntityByName( NULL, pEntity->m_iParent ); diff --git a/mp/src/game/server/physics.cpp b/mp/src/game/server/physics.cpp index bec86f5..2aa424a 100644 --- a/mp/src/game/server/physics.cpp +++ b/mp/src/game/server/physics.cpp @@ -1148,13 +1148,13 @@ void PhysSolidOverride( solid_t &solid, string_t overrideScript ) // suck out the comma delimited tokens and turn them into quoted key/values char szToken[256]; - const char *pStr = nexttoken(szToken, STRING(overrideScript), ','); + const char *pStr = nexttoken(szToken, STRING(overrideScript), ',', sizeof(szToken)); while ( szToken[0] != 0 ) { Q_strncat( pTmpString, "\"", sizeof(pTmpString), COPY_ALL_CHARACTERS ); Q_strncat( pTmpString, szToken, sizeof(pTmpString), COPY_ALL_CHARACTERS ); Q_strncat( pTmpString, "\" ", sizeof(pTmpString), COPY_ALL_CHARACTERS ); - pStr = nexttoken(szToken, pStr, ','); + pStr = nexttoken(szToken, pStr, ',', sizeof(szToken)); } // terminate the script Q_strncat( pTmpString, "}", sizeof(pTmpString), COPY_ALL_CHARACTERS ); diff --git a/mp/src/game/server/physics_prop_ragdoll.cpp b/mp/src/game/server/physics_prop_ragdoll.cpp index 72635ea..fec16e2 100644 --- a/mp/src/game/server/physics_prop_ragdoll.cpp +++ b/mp/src/game/server/physics_prop_ragdoll.cpp @@ -706,14 +706,14 @@ void CRagdollProp::InitRagdoll( const Vector &forceVector, int forceBone, const if ( m_anglesOverrideString != NULL_STRING && Q_strlen(m_anglesOverrideString.ToCStr()) > 0 ) { char szToken[2048]; - const char *pStr = nexttoken(szToken, STRING(m_anglesOverrideString), ','); + const char *pStr = nexttoken(szToken, STRING(m_anglesOverrideString), ',', sizeof(szToken)); // anglesOverride is index,angles,index,angles (e.g. "1, 22.5 123.0 0.0, 2, 0 0 0, 3, 0 0 180.0") while ( szToken[0] != 0 ) { int objectIndex = atoi(szToken); // sanity check to make sure this token is an integer Assert( atof(szToken) == ((float)objectIndex) ); - pStr = nexttoken(szToken, pStr, ','); + pStr = nexttoken(szToken, pStr, ',', sizeof(szToken)); Assert( szToken[0] ); if ( objectIndex >= m_ragdoll.listCount ) { @@ -740,7 +740,7 @@ void CRagdollProp::InitRagdoll( const Vector &forceVector, int forceBone, const MatrixSetColumn( out, 3, pBoneToWorld[boneIndex] ); element.pObject->SetPositionMatrix( pBoneToWorld[boneIndex], true ); } - pStr = nexttoken(szToken, pStr, ','); + pStr = nexttoken(szToken, pStr, ',', sizeof(szToken)); } } diff --git a/mp/src/game/server/util.cpp b/mp/src/game/server/util.cpp index 4b2008d..dd01d82 100644 --- a/mp/src/game/server/util.cpp +++ b/mp/src/game/server/util.cpp @@ -2064,13 +2064,17 @@ void UTIL_ValidateSoundName( string_t &name, const char *defaultStr ) // Input : token - Returns with a token, or zero length if the token was missing. // str - String to parse. // sep - Character to use as separator. UNDONE: allow multiple separator chars +// tokenLen - Length of token buffer // Output : Returns a pointer to the next token to be parsed. //----------------------------------------------------------------------------- -const char *nexttoken(char *token, const char *str, char sep) +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen) { if ((str == NULL) || (*str == '\0')) { - *token = '\0'; + if(tokenLen) + { + *token = '\0'; + } return(NULL); } @@ -2078,11 +2082,25 @@ const char *nexttoken(char *token, const char *str, char sep) // Copy everything up to the first separator into the return buffer. // Do not include separators in the return buffer. // - while ((*str != sep) && (*str != '\0')) + while ((*str != sep) && (*str != '\0') && (tokenLen > 1)) { *token++ = *str++; + tokenLen--; + } + + // + // If token is to big for return buffer, skip rest of token. + // + while ((*str != sep) && (*str != '\0')) + { + str++; + } + + if(tokenLen) + { + *token = '\0'; + tokenLen--; } - *token = '\0'; // // Advance the pointer unless we hit the end of the input string. diff --git a/mp/src/game/server/util.h b/mp/src/game/server/util.h index c06cbfe..05972bc 100644 --- a/mp/src/game/server/util.h +++ b/mp/src/game/server/util.h @@ -200,7 +200,7 @@ inline bool FStrEq( string_t str1, string_t str2 ) } #endif -const char *nexttoken(char *token, const char *str, char sep); +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen); // Misc. Prototypes void UTIL_SetSize (CBaseEntity *pEnt, const Vector &vecMin, const Vector &vecMax); diff --git a/mp/src/game/shared/ragdoll_shared.cpp b/mp/src/game/shared/ragdoll_shared.cpp index 0fc5077..194ffe0 100644 --- a/mp/src/game/shared/ragdoll_shared.cpp +++ b/mp/src/game/shared/ragdoll_shared.cpp @@ -90,9 +90,9 @@ public: if ( m_bSelfCollisions ) { char szToken[256]; - const char *pStr = nexttoken(szToken, pValue, ','); + const char *pStr = nexttoken(szToken, pValue, ',', sizeof(szToken)); int index0 = atoi(szToken); - nexttoken( szToken, pStr, ',' ); + nexttoken(szToken, pStr, ',' , sizeof(szToken)); int index1 = atoi(szToken); m_pSet->EnableCollisions( index0, index1 ); diff --git a/mp/src/game/shared/teamplay_round_timer.cpp b/mp/src/game/shared/teamplay_round_timer.cpp index e0739e7..c4ab756 100644 --- a/mp/src/game/shared/teamplay_round_timer.cpp +++ b/mp/src/game/shared/teamplay_round_timer.cpp @@ -1371,14 +1371,14 @@ void CTeamRoundTimer::InputAddTeamTime( inputdata_t &input ) int nSeconds = 0; // get the team - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); if ( token[0] ) { nTeam = Q_atoi( token ); } // get the time - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); if ( token[0] ) { nSeconds = Q_atoi( token ); diff --git a/sp/src/game/client/c_baseanimating.cpp b/sp/src/game/client/c_baseanimating.cpp index c41ff46..9b5509f 100644 --- a/sp/src/game/client/c_baseanimating.cpp +++ b/sp/src/game/client/c_baseanimating.cpp @@ -3528,7 +3528,7 @@ bool C_BaseAnimating::DispatchMuzzleEffect( const char *options, bool isFirstPer int weaponType = 0; // Get the first parameter - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); // Find the weapon type if ( token ) @@ -3572,7 +3572,7 @@ bool C_BaseAnimating::DispatchMuzzleEffect( const char *options, bool isFirstPer } // Get the second parameter - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); int attachmentIndex = -1; @@ -3683,7 +3683,7 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int // Get the particle effect name const char *p = options; - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if ( token ) { const char* mtoken = ModifyEventParticles( token ); @@ -3693,7 +3693,7 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int } // Get the attachment type - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if ( token ) { iAttachType = GetAttachTypeFromString( token ); @@ -3705,7 +3705,7 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int } // Get the attachment point index - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if ( token ) { iAttachment = atoi(token); @@ -3910,14 +3910,14 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int const char *p = options; // Bodygroup Name - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if ( token ) { Q_strncpy( szBodygroupName, token, sizeof(szBodygroupName) ); } // Get the desired value - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if ( token ) { value = atoi( token ); @@ -3957,21 +3957,21 @@ void C_BaseAnimating::FireObsoleteEvent( const Vector& origin, const QAngle& ang const char *p = options; - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if( token ) { Q_strncpy( effectFunc, token, sizeof(effectFunc) ); } - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if( token ) { iAttachment = atoi(token); } - p = nexttoken(token, p, ' '); + p = nexttoken(token, p, ' ', sizeof(token)); if( token ) { diff --git a/sp/src/game/client/cdll_util.cpp b/sp/src/game/client/cdll_util.cpp index 4e87753..6ad282b 100644 --- a/sp/src/game/client/cdll_util.cpp +++ b/sp/src/game/client/cdll_util.cpp @@ -727,13 +727,17 @@ CBaseEntity *CEntitySphereQuery::GetCurrentEntity() // Input : token - Returns with a token, or zero length if the token was missing. // str - String to parse. // sep - Character to use as separator. UNDONE: allow multiple separator chars +// tokenLen - Length of token buffer // Output : Returns a pointer to the next token to be parsed. //----------------------------------------------------------------------------- -const char *nexttoken(char *token, const char *str, char sep) +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen) { if ((str == NULL) || (*str == '\0')) { - *token = '\0'; + if(tokenLen) + { + *token = '\0'; + } return(NULL); } @@ -741,11 +745,25 @@ const char *nexttoken(char *token, const char *str, char sep) // Copy everything up to the first separator into the return buffer. // Do not include separators in the return buffer. // - while ((*str != sep) && (*str != '\0')) + while ((*str != sep) && (*str != '\0') && (tokenLen > 1)) { *token++ = *str++; + tokenLen--; + } + + // + // If token is to big for return buffer, skip rest of token. + // + while ((*str != sep) && (*str != '\0')) + { + str++; + } + + if(tokenLen) + { + *token = '\0'; + tokenLen--; } - *token = '\0'; // // Advance the pointer unless we hit the end of the input string. diff --git a/sp/src/game/client/cdll_util.h b/sp/src/game/client/cdll_util.h index 64beb5f..6e17327 100644 --- a/sp/src/game/client/cdll_util.h +++ b/sp/src/game/client/cdll_util.h @@ -89,7 +89,7 @@ void NormalizeAngles( QAngle& angles ); void InterpolateAngles( const QAngle& start, const QAngle& end, QAngle& output, float frac ); void InterpolateVector( float frac, const Vector& src, const Vector& dest, Vector& output ); -const char *nexttoken(char *token, const char *str, char sep); +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen); //----------------------------------------------------------------------------- // Base light indices to avoid index collision diff --git a/sp/src/game/client/hud_closecaption.cpp b/sp/src/game/client/hud_closecaption.cpp index f72b9fc..b286ff5 100644 --- a/sp/src/game/client/hud_closecaption.cpp +++ b/sp/src/game/client/hud_closecaption.cpp @@ -2356,11 +2356,11 @@ bool CHudCloseCaption::AddAsyncWork( const char *tokenstream, bool bIsStream, fl char tokenname[ 512 ]; tokenname[ 0 ] = 0; const char *p = tokenstream; - p = nexttoken( tokenname, p, ' ' ); + p = nexttoken(tokenname, p, ' ' , sizeof(tokenname)); // p points to reset of sentence tokens, build up a unicode string from them... while ( p && Q_strlen( tokenname ) > 0 ) { - p = nexttoken( tokenname, p, ' ' ); + p = nexttoken(tokenname, p, ' ' , sizeof(tokenname)); if ( Q_strlen( tokenname ) == 0 ) break; @@ -2395,7 +2395,7 @@ void CHudCloseCaption::ProcessSentenceCaptionStream( const char *tokenstream ) const char *p = tokenstream; - p = nexttoken( tokenname, p, ' ' ); + p = nexttoken(tokenname, p, ' ' , sizeof(tokenname)); if ( Q_strlen( tokenname ) > 0 ) { diff --git a/sp/src/game/server/baseentity.cpp b/sp/src/game/server/baseentity.cpp index b42f2ab..cb020f6 100644 --- a/sp/src/game/server/baseentity.cpp +++ b/sp/src/game/server/baseentity.cpp @@ -4821,7 +4821,7 @@ void CBaseEntity::PrecacheModelComponents( int nModelIndex ) { char token[256]; const char *pOptions = pEvent->pszOptions(); - nexttoken( token, pOptions, ' ' ); + nexttoken(token, pOptions, ' ' , sizeof(token)); if ( token ) { PrecacheParticleSystem( token ); diff --git a/sp/src/game/server/cbase.cpp b/sp/src/game/server/cbase.cpp index 19dd3ac..ba2cb05 100644 --- a/sp/src/game/server/cbase.cpp +++ b/sp/src/game/server/cbase.cpp @@ -132,7 +132,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the target name. // - const char *psz = nexttoken(szToken, ActionData, ','); + const char *psz = nexttoken(szToken, ActionData, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_iTarget = AllocPooledString(szToken); @@ -141,7 +141,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the input name. // - psz = nexttoken(szToken, psz, ','); + psz = nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_iTargetInput = AllocPooledString(szToken); @@ -154,7 +154,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the parameter override. // - psz = nexttoken(szToken, psz, ','); + psz = nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_iParameter = AllocPooledString(szToken); @@ -163,7 +163,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the delay. // - psz = nexttoken(szToken, psz, ','); + psz = nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_flDelay = atof(szToken); @@ -172,7 +172,7 @@ CEventAction::CEventAction( const char *ActionData ) // // Parse the number of times to fire. // - nexttoken(szToken, psz, ','); + nexttoken(szToken, psz, ',', sizeof(szToken)); if (szToken[0] != '\0') { m_nTimesToFire = atoi(szToken); diff --git a/sp/src/game/server/hl2/npc_BaseZombie.cpp b/sp/src/game/server/hl2/npc_BaseZombie.cpp index e7e5c6f..1ee291e 100644 --- a/sp/src/game/server/hl2/npc_BaseZombie.cpp +++ b/sp/src/game/server/hl2/npc_BaseZombie.cpp @@ -1616,7 +1616,7 @@ void CNPC_BaseZombie::HandleAnimEvent( animevent_t *pEvent ) const char *pString = pEvent->options; char token[128]; - pString = nexttoken( token, pString, ' ' ); + pString = nexttoken(token, pString, ' ' , sizeof(token)); int boneIndex = GetInteractionPartner()->LookupBone( token ); @@ -1626,7 +1626,7 @@ void CNPC_BaseZombie::HandleAnimEvent( animevent_t *pEvent ) return; } - pString = nexttoken( token, pString, ' ' ); + pString = nexttoken(token, pString, ' ' , sizeof(token)); if ( !token ) { diff --git a/sp/src/game/server/mapentities.cpp b/sp/src/game/server/mapentities.cpp index a08ad1e..0ee8220 100644 --- a/sp/src/game/server/mapentities.cpp +++ b/sp/src/game/server/mapentities.cpp @@ -86,7 +86,7 @@ string_t ExtractParentName(string_t parentName) return parentName; char szToken[256]; - nexttoken(szToken, STRING(parentName), ','); + nexttoken(szToken, STRING(parentName), ',', sizeof(szToken)); return AllocPooledString(szToken); } @@ -208,7 +208,7 @@ void SetupParentsForSpawnList( int nEntities, HierarchicalSpawn_t *pSpawnList ) if ( strchr(STRING(pEntity->m_iParent), ',') ) { char szToken[256]; - const char *pAttachmentName = nexttoken(szToken, STRING(pEntity->m_iParent), ','); + const char *pAttachmentName = nexttoken(szToken, STRING(pEntity->m_iParent), ',', sizeof(szToken)); pEntity->m_iParent = AllocPooledString(szToken); CBaseEntity *pParent = gEntList.FindEntityByName( NULL, pEntity->m_iParent ); diff --git a/sp/src/game/server/physics.cpp b/sp/src/game/server/physics.cpp index bec86f5..2aa424a 100644 --- a/sp/src/game/server/physics.cpp +++ b/sp/src/game/server/physics.cpp @@ -1148,13 +1148,13 @@ void PhysSolidOverride( solid_t &solid, string_t overrideScript ) // suck out the comma delimited tokens and turn them into quoted key/values char szToken[256]; - const char *pStr = nexttoken(szToken, STRING(overrideScript), ','); + const char *pStr = nexttoken(szToken, STRING(overrideScript), ',', sizeof(szToken)); while ( szToken[0] != 0 ) { Q_strncat( pTmpString, "\"", sizeof(pTmpString), COPY_ALL_CHARACTERS ); Q_strncat( pTmpString, szToken, sizeof(pTmpString), COPY_ALL_CHARACTERS ); Q_strncat( pTmpString, "\" ", sizeof(pTmpString), COPY_ALL_CHARACTERS ); - pStr = nexttoken(szToken, pStr, ','); + pStr = nexttoken(szToken, pStr, ',', sizeof(szToken)); } // terminate the script Q_strncat( pTmpString, "}", sizeof(pTmpString), COPY_ALL_CHARACTERS ); diff --git a/sp/src/game/server/physics_prop_ragdoll.cpp b/sp/src/game/server/physics_prop_ragdoll.cpp index 72635ea..fec16e2 100644 --- a/sp/src/game/server/physics_prop_ragdoll.cpp +++ b/sp/src/game/server/physics_prop_ragdoll.cpp @@ -706,14 +706,14 @@ void CRagdollProp::InitRagdoll( const Vector &forceVector, int forceBone, const if ( m_anglesOverrideString != NULL_STRING && Q_strlen(m_anglesOverrideString.ToCStr()) > 0 ) { char szToken[2048]; - const char *pStr = nexttoken(szToken, STRING(m_anglesOverrideString), ','); + const char *pStr = nexttoken(szToken, STRING(m_anglesOverrideString), ',', sizeof(szToken)); // anglesOverride is index,angles,index,angles (e.g. "1, 22.5 123.0 0.0, 2, 0 0 0, 3, 0 0 180.0") while ( szToken[0] != 0 ) { int objectIndex = atoi(szToken); // sanity check to make sure this token is an integer Assert( atof(szToken) == ((float)objectIndex) ); - pStr = nexttoken(szToken, pStr, ','); + pStr = nexttoken(szToken, pStr, ',', sizeof(szToken)); Assert( szToken[0] ); if ( objectIndex >= m_ragdoll.listCount ) { @@ -740,7 +740,7 @@ void CRagdollProp::InitRagdoll( const Vector &forceVector, int forceBone, const MatrixSetColumn( out, 3, pBoneToWorld[boneIndex] ); element.pObject->SetPositionMatrix( pBoneToWorld[boneIndex], true ); } - pStr = nexttoken(szToken, pStr, ','); + pStr = nexttoken(szToken, pStr, ',', sizeof(szToken)); } } diff --git a/sp/src/game/server/util.cpp b/sp/src/game/server/util.cpp index aba6f32..10fc071 100644 --- a/sp/src/game/server/util.cpp +++ b/sp/src/game/server/util.cpp @@ -2029,7 +2029,6 @@ void UTIL_ValidateSoundName( string_t &name, const char *defaultStr ) } } - //----------------------------------------------------------------------------- // Purpose: Slightly modified strtok. Does not modify the input string. Does // not skip over more than one separator at a time. This allows parsing @@ -2041,13 +2040,17 @@ void UTIL_ValidateSoundName( string_t &name, const char *defaultStr ) // Input : token - Returns with a token, or zero length if the token was missing. // str - String to parse. // sep - Character to use as separator. UNDONE: allow multiple separator chars +// tokenLen - Length of token buffer // Output : Returns a pointer to the next token to be parsed. //----------------------------------------------------------------------------- -const char *nexttoken(char *token, const char *str, char sep) +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen) { if ((str == NULL) || (*str == '\0')) { - *token = '\0'; + if(tokenLen) + { + *token = '\0'; + } return(NULL); } @@ -2055,11 +2058,25 @@ const char *nexttoken(char *token, const char *str, char sep) // Copy everything up to the first separator into the return buffer. // Do not include separators in the return buffer. // - while ((*str != sep) && (*str != '\0')) + while ((*str != sep) && (*str != '\0') && (tokenLen > 1)) { *token++ = *str++; + tokenLen--; + } + + // + // If token is to big for return buffer, skip rest of token. + // + while ((*str != sep) && (*str != '\0')) + { + str++; + } + + if(tokenLen) + { + *token = '\0'; + tokenLen--; } - *token = '\0'; // // Advance the pointer unless we hit the end of the input string. diff --git a/sp/src/game/server/util.h b/sp/src/game/server/util.h index a788da6..6e0e23d 100644 --- a/sp/src/game/server/util.h +++ b/sp/src/game/server/util.h @@ -200,7 +200,7 @@ inline bool FStrEq( string_t str1, string_t str2 ) } #endif -const char *nexttoken(char *token, const char *str, char sep); +const char *nexttoken(char *token, const char *str, char sep, size_t tokenLen); // Misc. Prototypes void UTIL_SetSize (CBaseEntity *pEnt, const Vector &vecMin, const Vector &vecMax); diff --git a/sp/src/game/shared/ragdoll_shared.cpp b/sp/src/game/shared/ragdoll_shared.cpp index e77e9a7..f859dbf 100644 --- a/sp/src/game/shared/ragdoll_shared.cpp +++ b/sp/src/game/shared/ragdoll_shared.cpp @@ -90,9 +90,9 @@ public: if ( m_bSelfCollisions ) { char szToken[256]; - const char *pStr = nexttoken(szToken, pValue, ','); + const char *pStr = nexttoken(szToken, pValue, ',', sizeof(szToken)); int index0 = atoi(szToken); - nexttoken( szToken, pStr, ',' ); + nexttoken(szToken, pStr, ',' , sizeof(szToken)); int index1 = atoi(szToken); m_pSet->EnableCollisions( index0, index1 ); diff --git a/sp/src/game/shared/teamplay_round_timer.cpp b/sp/src/game/shared/teamplay_round_timer.cpp index f993749..ed0f72a 100644 --- a/sp/src/game/shared/teamplay_round_timer.cpp +++ b/sp/src/game/shared/teamplay_round_timer.cpp @@ -1290,14 +1290,14 @@ void CTeamRoundTimer::InputAddTeamTime( inputdata_t &input ) int nSeconds = 0; // get the team - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); if ( token ) { nTeam = Q_atoi( token ); } // get the time - p = nexttoken( token, p, ' ' ); + p = nexttoken(token, p, ' ' , sizeof(token)); if ( token ) { nSeconds = Q_atoi( token );