Skip to content

Commit d279e3c

Browse files
authored
Fix crash caused by #3725 in CChat::CharacterKeyHandler (#4060)
1 parent a67781e commit d279e3c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Client/core/CChat.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,14 @@ bool CChat::CharacterKeyHandler(CGUIKeyEventArgs KeyboardArgs)
660660
{
661661
// If the input is a command, check that it isn't the 'login' command, if it is censor it
662662
char szInput[256];
663-
strncpy(szInput, m_strInputText.c_str() + 1, 256);
663+
unsigned int uiLength = sizeof(szInput) - 1;
664664

665-
const char* szCommand;
666-
if (szInput[0])
667-
szCommand = strtok(szInput, " ");
665+
strncpy(szInput, m_strInputText.c_str() + 1, uiLength);
666+
szInput[uiLength] = '\0';
668667

669-
if ((strcmp(szCommand, "login") != 0))
668+
const char* szCommand = strtok(szInput, " ");
669+
670+
if (szCommand && (strcmp(szCommand, "login") != 0))
670671
m_pInputHistory->Add(m_strInputText);
671672
else if ((m_pInputHistory->Empty() || m_pInputHistory->GetLast() != std::string("/login")))
672673
m_pInputHistory->Add("/login");

0 commit comments

Comments
 (0)