summaryrefslogtreecommitdiff
path: root/src/irc/irc_client.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-09-06 18:55:48 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-09-06 18:55:48 +0200
commit4cfcc79114d89096219039104674d35ca1aba5ca (patch)
tree11a0ab2d042dd4770c2f612523ac4a196c23e527 /src/irc/irc_client.cpp
parentc3309d0acfedaed867ae1bc14cd7a65fe5be1419 (diff)
downloadbiboumi-4cfcc79114d89096219039104674d35ca1aba5ca.tar.gz
biboumi-4cfcc79114d89096219039104674d35ca1aba5ca.tar.bz2
biboumi-4cfcc79114d89096219039104674d35ca1aba5ca.tar.xz
biboumi-4cfcc79114d89096219039104674d35ca1aba5ca.zip
Check the number of argument of every IRC command received from the server
Each IrcClient callback has a max and min size of argument, we call the callback only if the parsed message has a correct number of arguments, otherwise it is ignored (with a warning logged).
Diffstat (limited to 'src/irc/irc_client.cpp')
-rw-r--r--src/irc/irc_client.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index 4e8385c..6ab19b7 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -150,14 +150,26 @@ void IrcClient::parse_in_buffer(const size_t)
// Call the standard callback (if any), associated with the command
// name that we just received.
- auto cb = irc_callbacks.find(message.command);
- if (cb != irc_callbacks.end())
+ auto it = irc_callbacks.find(message.command);
+ if (it != irc_callbacks.end())
{
- try {
- (this->*(cb->second))(message);
- } catch (const std::exception& e) {
- log_error("Unhandled exception: " << e.what());
- }
+ const auto& limits = it->second.second;
+ // Check that the Message is well formed before actually calling
+ // the callback. limits.first is the min number of arguments,
+ // second is the max
+ if (message.arguments.size() < limits.first ||
+ (limits.second > 0 && message.arguments.size() > limits.second))
+ log_warning("Invalid number of arguments for IRC command “" << message.command <<
+ "”: " << message.arguments.size());
+ else
+ {
+ const auto& cb = it->second.first;
+ try {
+ (this->*(cb))(message);
+ } catch (const std::exception& e) {
+ log_error("Unhandled exception: " << e.what());
+ }
+ }
}
else
{