Fix buffer overflow when sending game messages as chat

This commit is contained in:
Anders Jenbo 2021-09-25 06:28:04 +02:00
commit c6468522c8
2 changed files with 8 additions and 7 deletions

View file

@ -75,7 +75,7 @@ void SetSpellLevelCheat(spell_id spl, int spllvl)
void PrintDebugMonster(int m)
{
char dstr[128];
char dstr[MAX_SEND_STR_LEN];
auto &monster = Monsters[m];
@ -748,7 +748,7 @@ void GetDebugMonster()
void NextDebugMonster()
{
char dstr[128];
char dstr[MAX_SEND_STR_LEN];
DebugMonsterId++;
if (DebugMonsterId == MAXMONSTERS)

View file

@ -1433,16 +1433,17 @@ void InitKeymapActions()
"GameInfo",
'V',
[] {
char pszStr[120];
char pszStr[MAX_SEND_STR_LEN];
const char *difficulties[3] = {
_("Normal"),
_("Nightmare"),
_("Hell"),
};
strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */
strncpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */
"{:s}, version = {:s}, mode = {:s}"),
gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty])
.c_str());
PROJECT_NAME, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty])
.c_str(),
MAX_SEND_STR_LEN - 1);
NetSendCmdString(1 << MyPlayerId, pszStr);
},
[&]() { return !IsPlayerDead(); },