I'm experiencing random crashes when players type some command in game chat. I can't reproduce it by myself no matter how hard I try. Crashes happen about 1-2 times a week.
Here is the code with the problem:
PHP Code:
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
if (!IsValidClient(client))
return Plugin_Continue;
if(sArgs[0] != '!' && sArgs[0] != '/')
return Plugin_Continue;
char arg[24];
strcopy(arg, sizeof(arg), sArgs);
bool charupper = false;
for(int i = 0; i <= strlen(arg); ++i)
{
if (IsCharUpper(arg[i]))
{
arg[i] = CharToLower(arg[i]);
charupper = true;
}
}
LogMessage("OnClientSayCommand");
LogMessage(arg);
char buffer[24] = "sm_";
int index = 3;
for(int i = 1; i != 16; ++i)
{
if(arg[i] == '\0' ||
arg[i] == ' ')
break;
buffer[index++] = arg[i];
}
buffer[index] = '\0';
LogMessage(buffer);
LogMessage(buffer[3]);
if((strlen(buffer) > 1 && GetCommandFlags(buffer) != INVALID_FCVAR_FLAGS) || (strlen(buffer[3]) > 1 && GetCommandFlags(buffer[3]) != INVALID_FCVAR_FLAGS))
{
LogMessage("GetCommandFlags post");
if (charupper)
{
FakeClientCommand(client, "say %s", arg);
return Plugin_Handled;
}
return Plugin_Continue;
}
LogMessage("MenuServer");
MenuServer(client, 0);
PrintToChat(client, "%t", "CommandExists");
return Plugin_Handled;
}
The idea is to check if a command exists, and if it doesn't show a menu.
Here is output at a crash monet:
Quote:
L 08/09/2020 - 17:14:11: [menuserver.smx] OnClientSayCommand
L 08/09/2020 - 17:14:11: [menuserver.smx] !ws
L 08/09/2020 - 17:14:11: [menuserver.smx] sm_ws
L 08/09/2020 - 17:14:11: [menuserver.smx] ws
L 08/09/2020 - 17:14:11: [menuserver.smx] MenuServer
L 08/09/2020 - 17:14:12: [menuserver.smx] OnClientSayCommand
L 08/09/2020 - 17:14:12: [menuserver.smx] !guns
L 08/09/2020 - 17:14:12: [menuserver.smx] sm_guns
L 08/09/2020 - 17:14:12: [menuserver.smx] guns
|
No "GetCommandFlags post" in the logs
It mostly happens if somebody types !NEGV (in capital), but sometimes the server crashes if another command is typed.
Trace stack shows that the problem is inside GetCommandFlags, but I can't get the reason. The only input value is the string, which is always correct.
Stack:
Quote:
0 sourcemod.2.csgo.so + 0x88800 int __cdecl SourceMod__NameHashSet_ConCommandBase __CommandFlagsHelper__ConCommandPolicy___retr ieve(int, char *s1, int)
eip = 0xec09e800 esp = 0xffb7c8c0 ebp = 0xffb7c8e8 ebx = 0x15cb0528
esi = 0x7e461212 edi = 0x7e46120c eax = 0x0ce70db8 ecx = 0x00000562
edx = 0x10d4a110 efl = 0x00210246
Found by: given as instruction pointer in context
Stack contents:
ffb7c8c0 b8 0d e7 0c 30 dd 0c 1d 08 c9 b7 ff 58 28 fc eb ....0.......X(..
ffb7c8d0 44 dd 0c 1d 10 a1 d4 10 3f 00 00 00 04 c9 b7 ff D.......?.......
ffb7c8e0 0f a1 d4 10 08 c9 b7 ff 18 c9 b7 ff 6f d5 09 ec ............o...
Possible instruction pointers:
1 sourcemod.2.csgo.so + 0x8756f GetCommandFlags(SourcePawn::IPluginContext *, int const*)
eip = 0xec09d56f esp = 0xffb7c8f0 ebp = 0xffb7c918
Found by: previous frame's frame pointer
Stack contents:
ffb7c8f0 50 fd 26 ec 0f a1 d4 10 08 c9 b7 ff a1 9e fb eb P.&.............
ffb7c900 d4 82 a6 0b 0f a1 d4 10 20 c9 b7 ff 68 49 d4 10 ........ ...hI..
ffb7c910 88 57 00 00 f8 a0 d4 10 48 c9 b7 ff 75 5f 61 e9 .W......H...u_a.
Possible instruction pointers::
|
SourceMod Version: 1.10.0.6492
Found similar question here
https://forums.alliedmods.net/showthread.php?t=306307 but no solution is proposed