From 3c32558a42201fd34daa32ad845c35591388369a Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 30 May 2015 22:34:09 +0200 Subject: degesch: properly unescape RPL_ISUPPORT values --- degesch.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/degesch.c b/degesch.c index f92c86b..97b804e 100644 --- a/degesch.c +++ b/degesch.c @@ -4486,6 +4486,25 @@ irc_handle_isupport_prefix (struct server *s, char *value) s->irc_channel_prefixes = xstrndup (prefixes, n_prefixes); } +static void +unescape_isupport_value (const char *value, struct str *output) +{ + const char *alphabet = "0123456789abcdef", *a, *b; + for (const char *p = value; *p; p++) + { + if (p[0] == '\\' + && p[1] == 'x' + && p[2] && (a = strchr (alphabet, tolower_ascii (p[2]))) + && p[3] && (b = strchr (alphabet, tolower_ascii (p[3])))) + { + str_append_c (output, (a - alphabet) << 4 | (b - alphabet)); + p += 3; + } + else + str_append_c (output, *p); + } +} + static void irc_handle_rpl_isupport (struct server *s, const struct irc_message *msg) { @@ -4499,8 +4518,14 @@ irc_handle_rpl_isupport (struct server *s, const struct irc_message *msg) char *value = param + strcspn (param, "="); if (*value) *value++ = '\0'; + struct str value_unescaped; + str_init (&value_unescaped); + unescape_isupport_value (value, &value_unescaped); + if (!strcmp (param, "PREFIX")) - irc_handle_isupport_prefix (s, value); + irc_handle_isupport_prefix (s, value_unescaped.str); + + str_free (&value_unescaped); } // TODO: initialize key_strxfrm according to server properties; -- cgit v1.2.3-70-g09d2