aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-30 22:34:09 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-30 22:34:09 +0200
commit3c32558a42201fd34daa32ad845c35591388369a (patch)
tree2c7fa2196b601d290cb19a868ab2a9f8c445cd7c
parentb7b84b489de975ff297cc35f12c2421903aec98c (diff)
downloadxK-3c32558a42201fd34daa32ad845c35591388369a.tar.gz
xK-3c32558a42201fd34daa32ad845c35591388369a.tar.xz
xK-3c32558a42201fd34daa32ad845c35591388369a.zip
degesch: properly unescape RPL_ISUPPORT values
-rw-r--r--degesch.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index f92c86b..97b804e 100644
--- a/degesch.c
+++ b/degesch.c
@@ -4487,6 +4487,25 @@ irc_handle_isupport_prefix (struct server *s, char *value)
}
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)
{
if (msg->params.len < 2)
@@ -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;