Skip to content
Permalink
Browse files Browse the repository at this point in the history
Avoid crash on commandPrefix message + hardening
  • Loading branch information
JustArchi committed Oct 14, 2020
1 parent cbbcc3a commit 4cd581e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ArchiSteamFarm/Bot.cs
Expand Up @@ -2241,6 +2241,12 @@ public sealed class Bot : IAsyncDisposable {
throw new ArgumentNullException(nameof(notification));
}

if ((notification.chat_group_id == 0) || (notification.chat_id == 0) || (notification.steamid_sender == 0)) {
ArchiLogger.LogNullError(nameof(notification.chat_group_id) + " || " + nameof(notification.chat_id) + " || " + nameof(notification.steamid_sender));

return;
}

// Under normal circumstances, timestamp must always be greater than 0, but Steam already proved that it's capable of going against the logic
if ((notification.steamid_sender != SteamID) && (notification.timestamp > 0)) {
if (ShouldAckChatMessage(notification.steamid_sender)) {
Expand Down Expand Up @@ -2277,6 +2283,12 @@ public sealed class Bot : IAsyncDisposable {
throw new ArgumentNullException(nameof(notification));
}

if (notification.steamid_friend == 0) {
ArchiLogger.LogNullError(nameof(notification.steamid_friend));

return;
}

if ((EChatEntryType) notification.chat_entry_type != EChatEntryType.ChatMsg) {
return;
}
Expand Down
14 changes: 12 additions & 2 deletions ArchiSteamFarm/Commands.cs
Expand Up @@ -307,7 +307,12 @@ public sealed class Commands {
return;
}

message = message.Substring(commandPrefix!.Length);
if (message.Length == commandPrefix!.Length) {
// If the message starts with command prefix and is of the same length as command prefix, then it's just empty command trigger, useless
return;
}

message = message.Substring(commandPrefix.Length);
}

Task<string?> responseTask = Response(steamID, message);
Expand Down Expand Up @@ -364,7 +369,12 @@ public sealed class Commands {
return;
}

message = message.Substring(commandPrefix!.Length);
if (message.Length == commandPrefix!.Length) {
// If the message starts with command prefix and is of the same length as command prefix, then it's just empty command trigger, useless
return;
}

message = message.Substring(commandPrefix.Length);
}

Task<string?> responseTask = Response(steamID, message);
Expand Down

0 comments on commit 4cd581e

Please sign in to comment.