Fix a bug where ban reason is used as ban duration (#2383)

In basebans there are 3 commands for banning: banip,addban,ban
They have required arguments for ban duration and optional arguments for ban reason. However the functions that process the arguments do not properly validate the duration and if reason is provided instead of duration, the functions just convert that string into an integer and use it as the ban duration. This usually results in a permaban with an empty reason. This commit adds a loop for checking duration chars to be numeric before converting them to an int.
This commit is contained in:
Lukáš Č.
2026-01-01 13:01:24 +01:00
committed by GitHub
parent 6e6f6e7479
commit 733e33e82a
2 changed files with 32 additions and 5 deletions
+23 -5
View File
@@ -76,8 +76,8 @@ public void OnPluginStart()
RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid|ip>");
RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <ip|#userid|name> <time> [reason]");
RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <minutes|0> <steamid> [reason]");
RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <ip|#userid|name> <minutes|0> [reason]");
//This to manage custom ban reason messages
RegConsoleCmd("sm_abortban", Command_AbortBan, "sm_abortban");
@@ -156,7 +156,7 @@ public Action Command_BanIp(int client, int args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_banip <ip|#userid|name> <time> [reason]");
ReplyToCommand(client, "[SM] Usage: sm_banip <ip|#userid|name> <minutes|0> [reason]");
return Plugin_Handled;
}
@@ -228,6 +228,15 @@ public Action Command_BanIp(int client, int args)
return Plugin_Handled;
}
for (int i = 0; i < strlen(time); i++)
{
if (!IsCharNumeric(time[i]))
{
ReplyToCommand(client, "[SM] Usage: sm_banip <ip|#userid|name> <minutes|0> [reason]");
return Plugin_Handled;
}
}
int minutes = StringToInt(time);
LogAction(client,
@@ -259,7 +268,7 @@ public Action Command_AddBan(int client, int args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
ReplyToCommand(client, "[SM] Usage: sm_addban <minutes|0> <steamid> [reason]");
return Plugin_Handled;
}
@@ -274,7 +283,7 @@ public Action Command_AddBan(int client, int args)
/* Get time */
if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
{
ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
ReplyToCommand(client, "[SM] Usage: sm_addban <minutes|0> <steamid> [reason]");
return Plugin_Handled;
}
total_len += len;
@@ -310,6 +319,15 @@ public Action Command_AddBan(int client, int args)
return Plugin_Handled;
}
for (int i = 0; i < strlen(time); i++)
{
if (!IsCharNumeric(time[i]))
{
ReplyToCommand(client, "[SM] Usage: sm_addban <minutes|0> <steamid> [reason]");
return Plugin_Handled;
}
}
int minutes = StringToInt(time);
LogAction(client,
+9
View File
@@ -315,6 +315,15 @@ public Action Command_Ban(int client, int args)
Arguments[0] = '\0';
}
for (int i = 0; i < strlen(s_time); i++)
{
if (!IsCharNumeric(s_time[i]))
{
ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
return Plugin_Handled;
}
}
playerinfo[client].banTargetUserId = GetClientUserId(target);
int time = StringToInt(s_time);