Skip to content

Commit

Permalink
fix crash for long kill feed weapons
Browse files Browse the repository at this point in the history
the "pizza_ya_san/weapon_as_shotgun" weapon name is so long it crashes clients when sent in the kill feed message.
  • Loading branch information
wootguy committed Oct 13, 2024
1 parent 6932e46 commit 26bec75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dlls/client_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ void ClientCommand(edict_t* pEntity)
pPlayer->pev->fixangle = TRUE;

// notify other clients of player switching to spectator mode
UTIL_ClientPrintAll(print_chat, UTIL_VarArgs("%s switched to spectator mode\n",
UTIL_ClientPrintAll(print_chat, UTIL_VarArgs("%s is now spectating\n",
(pev->netname && STRING(pev->netname)[0] != 0) ? STRING(pev->netname) : "\\disconnected\\"));
}
else
Expand Down
10 changes: 7 additions & 3 deletions dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,14 @@ void CHalfLifeMultiplay::DeathNotice( CBaseMonster *pVictim, entvars_t *pKiller,
}
}

// client crash if the killer name is too long
static char shortened_killer_name[30]; // client only has 32 char buffer which prepends "d_"
strcpy_safe(shortened_killer_name, killer_weapon_name, 30);

MESSAGE_BEGIN( MSG_ALL, gmsgDeathMsg );
WRITE_BYTE( killer_index ); // the killer
WRITE_BYTE(victim_index); // the victim
WRITE_STRING( killer_weapon_name ); // what they were killed by (should this be a string?)
WRITE_BYTE( killer_index ); // the killer
WRITE_BYTE(victim_index); // the victim
WRITE_STRING(shortened_killer_name); // what they were killed by (should this be a string?)
MESSAGE_END();

// restore player name and team info
Expand Down
2 changes: 2 additions & 0 deletions game_shared/shared_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#pragma once
#include <string.h>

// same as strncpy except it ensures the destination is null terminated, even if the buffer is too small
char* strcpy_safe(char* dest, const char* src, size_t size);

// same as strncat except it ensures the destination is null terminated, even if the buffer is too small
char* strcat_safe(char* dest, const char* src, size_t size);

0 comments on commit 26bec75

Please sign in to comment.