From eb1ce633848fb8c71b4d950a4b743ba434baca21 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Wed, 16 Nov 2022 05:01:03 +0500 Subject: [PATCH] More safe strncpy usage. --- cl_dll/statusbar.cpp | 5 +++-- dlls/3wave/threewave_gamerules.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cl_dll/statusbar.cpp b/cl_dll/statusbar.cpp index 0c02163c..0aaa8e26 100644 --- a/cl_dll/statusbar.cpp +++ b/cl_dll/statusbar.cpp @@ -78,11 +78,12 @@ void CHudStatusBar::ParseStatusString( int line_num ) GetPlayerInfo( indexval, &g_PlayerInfoList[indexval] ); if( g_PlayerInfoList[indexval].name != NULL ) { - strncpy( m_szName[line_num], g_PlayerInfoList[indexval].name, MAX_PLAYER_NAME_LENGTH ); + strncpy( m_szName[line_num], g_PlayerInfoList[indexval].name, MAX_PLAYER_NAME_LENGTH - 1 ); + m_szName[line_num][MAX_PLAYER_NAME_LENGTH - 1] = '\0'; } else { - strncpy( m_szName[line_num], "******", MAX_PLAYER_NAME_LENGTH ); + strcpy( m_szName[line_num], "******" ); } g_iNameColors = GetTeamIndex( indexval ); diff --git a/dlls/3wave/threewave_gamerules.cpp b/dlls/3wave/threewave_gamerules.cpp index ff2067cb..371fc92c 100644 --- a/dlls/3wave/threewave_gamerules.cpp +++ b/dlls/3wave/threewave_gamerules.cpp @@ -98,7 +98,8 @@ CThreeWave::CThreeWave() m_szTeamList[0] = 0; // Cache this because the team code doesn't want to deal with changing this in the middle of a game - strncpy( m_szTeamList, teamlist.string, TEAMPLAY_TEAMLISTLENGTH ); + strncpy( m_szTeamList, teamlist.string, TEAMPLAY_TEAMLISTLENGTH - 1 ); + m_szTeamList[TEAMPLAY_TEAMLISTLENGTH - 1] = '\0'; edict_t *pWorld = INDEXENT( 0 ); if( pWorld && pWorld->v.team ) @@ -108,7 +109,8 @@ CThreeWave::CThreeWave() const char *pTeamList = STRING( pWorld->v.team ); if( pTeamList && strlen( pTeamList ) ) { - strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH ); + strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH - 1 ); + m_szTeamList[TEAMPLAY_TEAMLISTLENGTH - 1] = '\0'; } } } @@ -1426,7 +1428,8 @@ void CThreeWave::RecountTeams() tm = num_teams; num_teams++; team_scores[tm] = 0; - strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH ); + strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH - 1 ); + team_names[tm][MAX_TEAMNAME_LENGTH - 1] = '\0'; } }