From 568f65213dc97988d8855bbb45445a3b2fd344af Mon Sep 17 00:00:00 2001 From: pajlada Date: Sat, 4 Dec 2021 16:37:53 +0100 Subject: [PATCH] Fix crash on missing parameters with IRC /kick command (#3382) --- CHANGELOG.md | 1 + src/providers/irc/IrcCommands.cpp | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a0983147..e9e1b0a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ - Bugfix: Fixed the first usercard being broken in `/mods` and `/vips` (#3349) - Bugfix: Fixed Chatterino attempting to send empty messages (#3355) - Bugfix: Fixed IRC highlights not triggering sounds or alerts properly. (#3368) +- Bugfix: Fixed IRC /kick command crashing if parameters were malformed. (#3382) - Dev: Add GitHub action to test builds without precompiled headers enabled. (#3327) - Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103) - Dev: Add benchmarks that can be compiled with the `BUILD_BENCHMARKS` CMake flag. Off by default. (#3038) diff --git a/src/providers/irc/IrcCommands.cpp b/src/providers/irc/IrcCommands.cpp index e6f5e2382..99bd5cb8c 100644 --- a/src/providers/irc/IrcCommands.cpp +++ b/src/providers/irc/IrcCommands.cpp @@ -55,11 +55,24 @@ Outcome invokeIrcCommand(const QString &commandName, const QString &allParams, } else if (cmd == "kick") { - if (paramsAfter(1).isEmpty()) - sendRaw("KICK " + params[0] + " " + params[1]); + if (params.size() < 2) + { + channel.addMessage( + makeSystemMessage("Usage: /kick [message]")); + return Failure; + } + const auto &channelParam = params[0]; + const auto &clientParam = params[1]; + const auto &messageParam = paramsAfter(1); + if (messageParam.isEmpty()) + { + sendRaw("KICK " + channelParam + " " + clientParam); + } else - sendRaw("KICK " + params[0] + " " + params[1] + " :" + - paramsAfter(1)); + { + sendRaw("KICK " + channelParam + " " + clientParam + " :" + + messageParam); + } } else if (cmd == "wallops") {