From e6424f42a7547314f34a616af8559c127c26eb69 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Wed, 16 Nov 2022 07:12:11 +0500 Subject: [PATCH] More safe strncpy usage. --- cl_dll/particlesys.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cl_dll/particlesys.cpp b/cl_dll/particlesys.cpp index 2fde5427..e200db7f 100644 --- a/cl_dll/particlesys.cpp +++ b/cl_dll/particlesys.cpp @@ -263,7 +263,8 @@ ParticleType *ParticleSystem::GetType( const char *szName ) ParticleType *ParticleSystem::AddPlaceholderType( const char *szName ) { m_pFirstType = new ParticleType( m_pFirstType ); - strncpy(m_pFirstType->m_szName, szName, sizeof(m_pFirstType->m_szName) ); + strncpy(m_pFirstType->m_szName, szName, sizeof(m_pFirstType->m_szName) - 1); + m_pFirstType->m_szName[sizeof(m_pFirstType->m_szName) - 1] = '\0'; return m_pFirstType; } @@ -285,8 +286,8 @@ ParticleType *ParticleSystem::ParseType( char *&szFile ) if ( !stricmp( szToken, "name" ) ) { szFile = gEngfuncs.COM_ParseFile(szFile,szToken); - strncpy(pType->m_szName, szToken, sizeof(pType->m_szName) ); - + strncpy(pType->m_szName, szToken, sizeof(pType->m_szName) - 1 ); + pType->m_szName[sizeof(pType->m_szName) - 1] = '\0'; ParticleType *pTemp = GetType(szToken); if (pTemp) {