From 368fdf12591b5a86f4f2d1b1485384f1c8df66f7 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Mon, 14 Nov 2022 08:19:12 +0500 Subject: [PATCH] More safe _snprintf usage. --- dlls/client.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index 32740dc5..e81e6772 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -109,7 +109,10 @@ void ClientDisconnect( edict_t *pEntity ) char text[256] = ""; if( pEntity->v.netname ) - _snprintf( text, sizeof(text), "- %s has left the game\n", STRING( pEntity->v.netname ) ); + { + _snprintf( text, sizeof(text) - 1, "- %s has left the game\n", STRING( pEntity->v.netname ) ); + text[sizeof(text) - 1] = '\0'; + } MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL ); WRITE_BYTE( ENTINDEX( pEntity ) ); WRITE_STRING( text ); @@ -667,7 +670,8 @@ void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer ) if( gpGlobals->maxClients > 1 ) { char text[256]; - _snprintf( text, 256, "* %s changed name to %s\n", STRING( pEntity->v.netname ), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) ); + _snprintf( text, sizeof(text) - 1, "* %s changed name to %s\n", STRING( pEntity->v.netname ), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) ); + text[sizeof(text) - 1] = '\0'; MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL ); WRITE_BYTE( ENTINDEX( pEntity ) ); WRITE_STRING( text );