From 4b3bb4cd81574c57cf12327ec92a75f1de990361 Mon Sep 17 00:00:00 2001 From: YoYo-178 <95132723+YoYo178@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:53:01 +0530 Subject: [PATCH] fix buffer overflows --- mp/src/game/client/ff/hud/ff_hud_cellcount.cpp | 2 +- mp/src/game/client/ff/hud/ff_hud_hitindicator.cpp | 4 ++-- mp/src/game/client/ff/hud/ff_hud_menu.cpp | 4 ++-- mp/src/game/client/ff/hud/ff_hud_speedometer.cpp | 4 ++-- mp/src/game/client/ff/hud/ff_hud_teamscores.cpp | 6 +++--- .../client/game_controls/ClientScoreBoardDialog.cpp | 10 +++++----- mp/src/game/client/game_controls/classmenu.cpp | 2 +- mp/src/game/client/game_controls/teammenu.cpp | 4 ++-- mp/src/game/client/hud_crosshair.cpp | 6 +++--- mp/src/game/client/hud_numericdisplay.cpp | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/mp/src/game/client/ff/hud/ff_hud_cellcount.cpp b/mp/src/game/client/ff/hud/ff_hud_cellcount.cpp index 2903ff77..e5f12320 100644 --- a/mp/src/game/client/ff/hud/ff_hud_cellcount.cpp +++ b/mp/src/game/client/ff/hud/ff_hud_cellcount.cpp @@ -177,7 +177,7 @@ void CHudCellCount::Paint() // Get the class as a string wchar_t unicode[6]; - swprintf(unicode, L"%d", m_iCellCount); + V_snwprintf(unicode, sizeof(unicode), L"%d", m_iCellCount); // Draw text surface()->DrawSetTextFont( m_hTextFont ); diff --git a/mp/src/game/client/ff/hud/ff_hud_hitindicator.cpp b/mp/src/game/client/ff/hud/ff_hud_hitindicator.cpp index daf378a1..7a972cd9 100644 --- a/mp/src/game/client/ff/hud/ff_hud_hitindicator.cpp +++ b/mp/src/game/client/ff/hud/ff_hud_hitindicator.cpp @@ -249,7 +249,7 @@ void CHudHitIndicator::Paint( void ) int charOffsetX = surface()->GetCharacterWidth(currentFont, outerChar) / 2; int charOffsetY = surface()->GetFontTall(currentFont) / 2; - swprintf(unicode, L"%c", outerChar); + V_snwprintf(unicode, sizeof(unicode), L"%c", outerChar); surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY); surface()->DrawUnicodeChar(unicode[0]); @@ -262,7 +262,7 @@ void CHudHitIndicator::Paint( void ) charOffsetX = surface()->GetCharacterWidth(currentFont, innerChar) / 2; charOffsetY = surface()->GetFontTall(currentFont) / 2; - swprintf(unicode, L"%c", innerChar); + V_snwprintf(unicode, sizeof(unicode), L"%c", innerChar); surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY); surface()->DrawUnicodeChar(unicode[0]); diff --git a/mp/src/game/client/ff/hud/ff_hud_menu.cpp b/mp/src/game/client/ff/hud/ff_hud_menu.cpp index 51dbd87a..c89df462 100644 --- a/mp/src/game/client/ff/hud/ff_hud_menu.cpp +++ b/mp/src/game/client/ff/hud/ff_hud_menu.cpp @@ -712,7 +712,7 @@ void CHudContextMenu::Paint() int iconOffsetY = surface()->GetFontTall(m_hMenuIcon) / 2; wchar_t unicode[2]; - swprintf(unicode, L"%c", character); + V_snwprintf(unicode, sizeof(unicode), L"%c", character); surface()->DrawSetTextPos(m_flPositions[i][0] - iconOffsetX, m_flPositions[i][1] - iconOffsetY); surface()->DrawUnicodeChar(unicode[0]); @@ -740,7 +740,7 @@ void CHudContextMenu::Paint() int textHeightX = surface()->GetFontTall(m_hTextFont); surface()->DrawSetTextPos(m_flPositions[i][0] - numberOffsetX, m_flPositions[i][1] + iconOffsetY + py + textHeightX); - swprintf(unicode, L"%c", chDisplay); + V_snwprintf(unicode, sizeof(unicode), L"%c", chDisplay); surface()->DrawUnicodeChar(unicode[0]); } diff --git a/mp/src/game/client/ff/hud/ff_hud_speedometer.cpp b/mp/src/game/client/ff/hud/ff_hud_speedometer.cpp index 56838ca1..31a6deb8 100644 --- a/mp/src/game/client/ff/hud/ff_hud_speedometer.cpp +++ b/mp/src/game/client/ff/hud/ff_hud_speedometer.cpp @@ -194,7 +194,7 @@ void CHudSpeedometer::Paint() surface()->DrawSetTextPos( SpeedFont_xpos, SpeedFont_ypos ); wchar_t unicode[6]; - swprintf(unicode, L"%d", (int)m_iVelocity); + V_snwprintf(unicode, sizeof(unicode), L"%d", (int)m_iVelocity); for( wchar_t *wch = unicode; *wch != 0; wch++ ) surface()->DrawUnicodeChar( *wch ); @@ -237,7 +237,7 @@ void CHudSpeedometer::Paint() surface()->DrawSetTextColor( speedColor ); wchar_t unicode[6]; - swprintf(unicode, L"%d", (int)m_flAvgVelocity); + V_snwprintf(unicode, sizeof(unicode), L"%d", (int)m_flAvgVelocity); for( wchar_t *wch = unicode; *wch != 0; wch++ ) surface()->DrawUnicodeChar( *wch ); diff --git a/mp/src/game/client/ff/hud/ff_hud_teamscores.cpp b/mp/src/game/client/ff/hud/ff_hud_teamscores.cpp index 5a6a33e5..e6ddef7e 100644 --- a/mp/src/game/client/ff/hud/ff_hud_teamscores.cpp +++ b/mp/src/game/client/ff/hud/ff_hud_teamscores.cpp @@ -163,7 +163,7 @@ void CHudTeamScores::PaintNumbersRightAligned(HFont font, int xpos, int ypos, in int iTempxpos = xpos + charWidth * maxchars; // allow for X characters of score wchar_t unicode[6]; - swprintf(unicode, L"%d", value); + V_snwprintf(unicode, sizeof(unicode), L"%d", value); surface()->DrawSetTextFont( font ); @@ -185,7 +185,7 @@ void CHudTeamScores::PaintNumbers(HFont font, int xpos, int ypos, int value) { surface()->DrawSetTextFont(font); wchar_t unicode[6]; - swprintf(unicode, L"%d", value); + V_snwprintf(unicode, sizeof(unicode), L"%d", value); surface()->DrawSetTextPos(xpos, ypos); surface()->DrawUnicodeString( unicode ); -} \ No newline at end of file +} diff --git a/mp/src/game/client/game_controls/ClientScoreBoardDialog.cpp b/mp/src/game/client/game_controls/ClientScoreBoardDialog.cpp index e97c41ff..262b863f 100644 --- a/mp/src/game/client/game_controls/ClientScoreBoardDialog.cpp +++ b/mp/src/game/client/game_controls/ClientScoreBoardDialog.cpp @@ -622,7 +622,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void ) } else { - swprintf( szName, L"%s - (%i players)", szTeamName, iNumPlayers ); + V_snwprintf( szName, sizeof(szName), L"%s - (%i players)", szTeamName, iNumPlayers ); szTeamName = szName; } @@ -630,7 +630,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void ) // Look up team fort points (currently hacked to get team score (frags) which is what was previously used) wchar_t szFortPoints[ 6 ]; - swprintf( szFortPoints, L"%d", pGR->GetTeamScore( iTeam ) ); + V_snwprintf( szFortPoints, sizeof(szFortPoints), L"%d", pGR->GetTeamScore( iTeam ) ); // Display team fort points (probably will actually be team score e.g. captures *10) m_pPlayerList->ModifyColumn( i, "fortpoints", szFortPoints ); @@ -638,7 +638,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void ) // AfterShock - commented this out so teamfrags arent shown (and scores are clearer) // Look up team score (frags) //wchar_t szScore[ 6 ]; - //swprintf( szScore, L"%d", pGR->GetTeamScore( iTeam ) ); + //V_snwprintf( szScore, sizeof(szScore), L"%d", pGR->GetTeamScore( iTeam ) ); // Display team frags //m_pPlayerList->ModifyColumn( i, "score", szScore ); @@ -647,7 +647,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void ) // AfterShock - commented this out so teamdeaths arent shown (and scores are clearer) // Look up team deaths //wchar_t szDeaths[ 6 ]; - //swprintf( szDeaths, L"%d", pGR->GetTeamDeaths( iTeam ) ); + //V_snwprintf( szDeaths, sizeof(szDeaths), L"%d", pGR->GetTeamDeaths( iTeam ) ); // Display team deaths //m_pPlayerList->ModifyColumn( i, "deaths", szDeaths ); @@ -664,7 +664,7 @@ void CClientScoreBoardDialog::UpdateHeaders( void ) else { wchar_t szLatency[ 12 ]; - swprintf( szLatency, L"%i", iLatency ); + V_snwprintf( szLatency, sizeof(szLatency), L"%i", iLatency ); m_pPlayerList->ModifyColumn( i, "ping", szLatency ); } } diff --git a/mp/src/game/client/game_controls/classmenu.cpp b/mp/src/game/client/game_controls/classmenu.cpp index 49ce7f80..79bea91c 100644 --- a/mp/src/game/client/game_controls/classmenu.cpp +++ b/mp/src/game/client/game_controls/classmenu.cpp @@ -154,7 +154,7 @@ class LoadoutLabel : public Label char character = pIcon->cCharacterInFont; wchar_t unicode[2]; - swprintf(unicode, L"%c", character); + V_snwprintf(unicode, sizeof(unicode), L"%c", character); surface()->DrawSetTextColor(Color(255, 255, 255, 255)); surface()->DrawSetTextFont(hFont); diff --git a/mp/src/game/client/game_controls/teammenu.cpp b/mp/src/game/client/game_controls/teammenu.cpp index 7bcc4ad9..5be6d4ae 100644 --- a/mp/src/game/client/game_controls/teammenu.cpp +++ b/mp/src/game/client/game_controls/teammenu.cpp @@ -462,7 +462,7 @@ void CTeamMenu::UpdateTeamButtons() if (szTeamName) { - swprintf( szName, L"%c. %s", wchTeamNumber, szTeamName ); + V_snwprintf( szName, sizeof(szName), L"%c. %s", wchTeamNumber, szTeamName ); szTeamName = szName; } else @@ -482,7 +482,7 @@ void CTeamMenu::UpdateTeamButtons() else { // no name, just use the number - swprintf( szTeamName, L"%c.", wchTeamNumber ); + V_snwprintf( szTeamName, sizeof(szTeamName), L"%c.", wchTeamNumber ); pTeamButton->SetText(szTeamName); } diff --git a/mp/src/game/client/hud_crosshair.cpp b/mp/src/game/client/hud_crosshair.cpp index e4a2a1a7..d2841516 100644 --- a/mp/src/game/client/hud_crosshair.cpp +++ b/mp/src/game/client/hud_crosshair.cpp @@ -417,7 +417,7 @@ void CHudCrosshair::Paint(void) int charOffsetX = surface()->GetCharacterWidth(currentFont, outerChar) / 2; int charOffsetY = surface()->GetFontTall(currentFont) / 2; - swprintf(unicode, L"%c", outerChar); + V_snwprintf(unicode, sizeof(unicode), L"%c", outerChar); surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY); surface()->DrawUnicodeChar(unicode[0]); @@ -430,7 +430,7 @@ void CHudCrosshair::Paint(void) charOffsetX = surface()->GetCharacterWidth(currentFont, innerChar) / 2; charOffsetY = surface()->GetFontTall(currentFont) / 2; - swprintf(unicode, L"%c", innerChar); + V_snwprintf(unicode, sizeof(unicode), L"%c", innerChar); surface()->DrawSetTextPos(x - charOffsetX, y - charOffsetY); surface()->DrawUnicodeChar(unicode[0]); @@ -557,4 +557,4 @@ void CHudCrosshair::SetCrosshair(CHudTexture* texture, const Color& clr) void CHudCrosshair::ResetCrosshair() { SetCrosshair(m_pDefaultCrosshair, Color(255, 255, 255, 255)); -} \ No newline at end of file +} diff --git a/mp/src/game/client/hud_numericdisplay.cpp b/mp/src/game/client/hud_numericdisplay.cpp index 20b97825..b9076c69 100644 --- a/mp/src/game/client/hud_numericdisplay.cpp +++ b/mp/src/game/client/hud_numericdisplay.cpp @@ -154,7 +154,7 @@ void CHudNumericDisplay::PaintNumbersRightAligned(HFont font, int xpos, int ypos int iTempxpos = xpos + charWidth * maxchars; // allow for X characters of score wchar_t unicode[6]; - swprintf(unicode, L"%d", value); + V_snwprintf(unicode, sizeof(unicode), L"%d", value); surface()->DrawSetTextFont(font);