From 8843d4f77d8e829135e2ff9b354990134c58c46a Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 21 Oct 2017 20:00:25 -0700 Subject: [PATCH 1/3] Strip : from parameters This is to fix #601. The function used to extract the mode string assumed that ":" would only occur in a particular spot. This lead to the possibility that ":" could be treated as part of things like nicknames or mode arguments, where it should have been stripped as part of protocol escaping. --- src/fe-common/irc/fe-events.c | 2 +- src/irc/core/irc.c | 32 ++++++++++++++++++++++++++++++-- src/irc/core/modes.c | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index 850174c5..cc83d476 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -224,7 +224,7 @@ static void event_nick(IRC_SERVER_REC *server, const char *data, static void event_mode(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr) { - char *params, *channel, *mode; + char *params = NULL, *channel = NULL, *mode = NULL; g_return_if_fail(data != NULL); diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index 4dce3fcf..790c7122 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -40,6 +40,8 @@ static int signal_server_incoming; # define MAX_SOCKET_READS 5 #endif +static void strip_params_colon(char *const); + /* The core of the irc_send_cmd* functions. If `raw' is TRUE, the `cmd' won't be checked at all if it's 512 bytes or not, or if it contains line feeds or not. Use with extreme caution! */ @@ -269,8 +271,9 @@ char *event_get_params(const char *data, int count, ...) while (count-- > 0) { str = (char **) va_arg(args, char **); if (count == 0 && rest) { - /* put the rest to last parameter */ - tmp = *datad == ':' ? datad+1 : datad; + /* Put the rest into the last parameter. */ + strip_params_colon(datad); + tmp = datad; } else { tmp = event_get_param(&datad); } @@ -281,6 +284,31 @@ char *event_get_params(const char *data, int count, ...) return duprec; } +/* Given a string containing , strip any colon prefixing . */ +static void strip_params_colon(char *const params) +{ + if (!params) { + return; + } + + char *s = params; + while (*s != '\0') { + if (*s == ':') { + memmove(s, s+1, strlen(s+1)+1); + return; + } + + s = strchr(s, ' '); + if (!s) { + return; + } + + while (*s == ' ') { + s++; + } + } +} + static void irc_server_event(IRC_SERVER_REC *server, const char *line, const char *nick, const char *address) { diff --git a/src/irc/core/modes.c b/src/irc/core/modes.c index cc3d0faf..ecbf2571 100644 --- a/src/irc/core/modes.c +++ b/src/irc/core/modes.c @@ -480,8 +480,8 @@ static void event_user_mode(IRC_SERVER_REC *server, const char *data) static void event_mode(IRC_SERVER_REC *server, const char *data, const char *nick) { - IRC_CHANNEL_REC *chanrec; - char *params, *channel, *mode; + IRC_CHANNEL_REC *chanrec = NULL; + char *params = NULL, *channel = NULL, *mode = NULL; g_return_if_fail(data != NULL); From 1a49787ef25103d1a393c81e35fb949322fe0523 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Mon, 27 Nov 2017 19:37:11 -0800 Subject: [PATCH 2/3] Revert initializing pointers to NULL To maintain C89 compatibility --- src/fe-common/irc/fe-events.c | 2 +- src/irc/core/modes.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index cc83d476..850174c5 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -224,7 +224,7 @@ static void event_nick(IRC_SERVER_REC *server, const char *data, static void event_mode(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr) { - char *params = NULL, *channel = NULL, *mode = NULL; + char *params, *channel, *mode; g_return_if_fail(data != NULL); diff --git a/src/irc/core/modes.c b/src/irc/core/modes.c index ecbf2571..cc3d0faf 100644 --- a/src/irc/core/modes.c +++ b/src/irc/core/modes.c @@ -480,8 +480,8 @@ static void event_user_mode(IRC_SERVER_REC *server, const char *data) static void event_mode(IRC_SERVER_REC *server, const char *data, const char *nick) { - IRC_CHANNEL_REC *chanrec = NULL; - char *params = NULL, *channel = NULL, *mode = NULL; + IRC_CHANNEL_REC *chanrec; + char *params, *channel, *mode; g_return_if_fail(data != NULL); From b0637ad6ea8784d3b2be829ca40f9dddf0c049fc Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 2 Dec 2017 10:09:52 -0800 Subject: [PATCH 3/3] Update NULL comparison style and be C89 compatible --- src/irc/core/irc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index 790c7122..a740b0da 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -287,11 +287,13 @@ char *event_get_params(const char *data, int count, ...) /* Given a string containing , strip any colon prefixing . */ static void strip_params_colon(char *const params) { - if (!params) { + char *s; + + if (params == NULL) { return; } - char *s = params; + s = params; while (*s != '\0') { if (*s == ':') { memmove(s, s+1, strlen(s+1)+1); @@ -299,7 +301,7 @@ static void strip_params_colon(char *const params) } s = strchr(s, ' '); - if (!s) { + if (s == NULL) { return; }