From 25f25073b9334fa2996678fc73c1729ce3d83839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 7 Aug 2022 23:28:11 +0200 Subject: [PATCH] irc: fix parsing of messages with trailing spaces and no trailing parameter (closes #1803) --- ChangeLog.adoc | 1 + src/plugins/irc/irc-message.c | 9 +-------- tests/unit/plugins/irc/test-irc-message.cpp | 14 ++++++++++++-- tests/unit/plugins/irc/test-irc-protocol.cpp | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 91038a0d6..77f6419c1 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -31,6 +31,7 @@ Bug fixes:: * irc: fix duplicated channels in autojoin option when autojoin_dynamic is enabled (issue #1795) * irc: fix display of TOPIC and QUIT messages with an empty trailing parameter (issue #1797) + * irc: fix parsing of messages with trailing spaces and no trailing parameter (issue #1803) * guile: fix function hdata_get_string * javascript: fix return of long value in functions infolist_time, hdata_long and hdata_time * php: fix function hdata_compare diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index febf7b9da..64a37a3e7 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -59,7 +59,7 @@ void irc_message_parse_params (const char *parameters, char ***params, int *num_params) { - const char *ptr_params, *pos_end, *pos_next; + const char *ptr_params, *pos_end; char **new_params; int alloc_params, trailing; @@ -104,13 +104,6 @@ irc_message_parse_params (const char *parameters, } if (!pos_end) pos_end = ptr_params + strlen (ptr_params); - pos_next = pos_end; - while (pos_next[0] == ' ') - { - pos_next++; - } - if (!pos_next[0]) - pos_end = pos_next; if (params) { alloc_params++; diff --git a/tests/unit/plugins/irc/test-irc-message.cpp b/tests/unit/plugins/irc/test-irc-message.cpp index ad469d46f..a860f2f30 100644 --- a/tests/unit/plugins/irc/test-irc-message.cpp +++ b/tests/unit/plugins/irc/test-irc-message.cpp @@ -355,6 +355,16 @@ TEST(IrcMessage, ParseParams) POINTERS_EQUAL(NULL, params[1]); string_free_split (params); + /* single parameter with trailing space */ + params = NULL; + num_params = -1; + irc_message_parse_params ("param1 ", ¶ms, &num_params); + LONGS_EQUAL(1, num_params); + CHECK(params); + STRCMP_EQUAL("param1", params[0]); + POINTERS_EQUAL(NULL, params[1]); + string_free_split (params); + /* two parameters */ params = NULL; num_params = -1; @@ -373,7 +383,7 @@ TEST(IrcMessage, ParseParams) LONGS_EQUAL(2, num_params); CHECK(params); STRCMP_EQUAL("param1", params[0]); - STRCMP_EQUAL("param2 ", params[1]); + STRCMP_EQUAL("param2", params[1]); POINTERS_EQUAL(NULL, params[2]); string_free_split (params); @@ -384,7 +394,7 @@ TEST(IrcMessage, ParseParams) LONGS_EQUAL(2, num_params); CHECK(params); STRCMP_EQUAL("param1", params[0]); - STRCMP_EQUAL("param2 ", params[1]); + STRCMP_EQUAL("param2", params[1]); POINTERS_EQUAL(NULL, params[2]); string_free_split (params); diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index 9d3c34864..c3d3872aa 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -2003,7 +2003,7 @@ TEST(IrcProtocolWithServer, wallops) CHECK_ERROR_PARAMS("wallops", 0, 1); RECV(":alice!user@host WALLOPS message "); - CHECK_SRV("-- Wallops from alice (user@host): message "); + CHECK_SRV("-- Wallops from alice (user@host): message"); RECV(":alice!user@host WALLOPS :message from admin "); CHECK_SRV("-- Wallops from alice (user@host): message from admin ");