Skip to content

Commit e83ecdf

Browse files
dimhotepusEricS-Valve
authored andcommitted
server: Ensure no buffer overflows when sscanf to char buffer
Closes #878
1 parent bdb5753 commit e83ecdf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/game/server/tf/tf_passtime_logic.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,11 +1853,14 @@ bool CTFPasstimeLogic::ParseSetSection( const char *pStr, SetSectionParams &s )
18531853
{
18541854
char pszStartName[64];
18551855
char pszEndName[64];
1856-
const int iScanCount = sscanf( pStr, "%i %s %s", &s.num, pszStartName, pszEndName ); // WHAT YEAR IS IT
1856+
const int iScanCount = sscanf( pStr, "%i %63s %63s", &s.num, pszStartName, pszEndName ); // WHAT YEAR IS IT
18571857
if ( iScanCount != 3 )
18581858
{
18591859
return false;
18601860
}
1861+
pszStartName[ ARRAYSIZE(pszStartName) - 1 ] = '\0';
1862+
pszEndName[ ARRAYSIZE(pszEndName) - 1 ] = '\0';
1863+
18611864
s.pSectionStart = dynamic_cast<CPathTrack*>( gEntList.FindEntityByName( 0, pszStartName ) );
18621865
s.pSectionEnd = dynamic_cast<CPathTrack*>( gEntList.FindEntityByName( 0, pszEndName ) );
18631866

src/game/server/tf/tf_player.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5950,8 +5950,9 @@ void CTFPlayer::HandleAnimEvent( animevent_t *pEvent )
59505950
char szAttrName[128];
59515951
float flVal;
59525952
float flDuration;
5953-
if ( sscanf( pEvent->options, "%s %f %f", szAttrName, &flVal, &flDuration ) == 3 )
5953+
if ( sscanf( pEvent->options, "%127s %f %f", szAttrName, &flVal, &flDuration ) == 3 )
59545954
{
5955+
szAttrName[ ARRAYSIZE(szAttrName) - 1 ] = '\0';
59555956
Assert( flDuration > 0.f );
59565957
AddCustomAttribute( szAttrName, flVal, flDuration );
59575958
}

0 commit comments

Comments
 (0)