From db111569018901e4464fd0817f996d9caf530c30 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Wed, 12 Jun 2024 19:27:57 -0700 Subject: [PATCH] Filter [ out of Rejecting K-Lined user snote This snote is generated earlier than any other snote that called get_client_name which causes it to potentially have the wrong username in the message. The extra [ can result in an ambiguous parse as well. --- ircd/s_conf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ircd/s_conf.c b/ircd/s_conf.c index 560d1ba7..20ecd185 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -299,6 +299,23 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern return (i); } +/* + * Remove all occurences of needle from haystack in-place. + * + * inputs - string to filter + * - character to remove + * side effect - all occurences of needle removed from haystack + */ +static void +filter_string(char *haystack, char needle) +{ + int o = 0; + for (int i = 0; haystack[i] != '\0'; i++) + if (haystack[i] != needle) + haystack[o++] = haystack[i]; + haystack[o] = '\0'; +} + /* * verify_access * @@ -367,6 +384,9 @@ verify_access(struct Client *client_p, const char *username) me.name, client_p->name, get_user_ban_reason(aconf)); + // this snote is sent before username has been cleaned + filter_string(client_p->username, '['); + sendto_realops_snomask(SNO_BANNED, L_NETWIDE, "Rejecting K-Lined user %s [%s] (%s@%s)", get_client_name(client_p, HIDE_IP), show_ip(NULL, client_p) ? client_p->sockhost : "255.255.255.255", aconf->user, aconf->host);