From 5b151d1639f4656f79b92b7b495251b51bc10d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 21 Jun 2020 10:22:37 +0200 Subject: irc: check that the first nick char is not a prefix char or chantype in function irc_nick_is_nick --- src/plugins/irc/irc-nick.c | 15 ++++++++++++--- src/plugins/irc/irc-nick.h | 4 ++-- src/plugins/irc/irc-server.h | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/plugins/irc') diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 277bd0cf7..29ad77d74 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -72,13 +72,17 @@ irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick) int irc_nick_is_nick (struct t_irc_server *server, const char *string) { - const char *ptr_string; + const char *ptr_string, *ptr_prefix_chars, *ptr_chantypes; int utf8mapping; if (!string || !string[0]) return 0; utf8mapping = (server) ? server->utf8mapping : IRC_SERVER_UTF8MAPPING_NONE; + ptr_prefix_chars = (server && server->prefix_chars) ? + server->prefix_chars : irc_server_prefix_chars_default; + ptr_chantypes = (server && server->chantypes) ? + server->chantypes : irc_channel_default_chantypes; /* check length of nick in bytes (if we have a limit in the server) */ if (server && (server->nick_max_length > 0) @@ -103,18 +107,23 @@ irc_nick_is_nick (struct t_irc_server *server, const char *string) /* first char is invalid */ return 0; } + if (strchr (ptr_prefix_chars, string[0]) + || strchr (ptr_chantypes, string[0])) + { + return 0; + } /* check if there are forbidden chars in nick */ ptr_string = string; while (ptr_string && ptr_string[0]) { if ((utf8mapping == IRC_SERVER_UTF8MAPPING_NONE) - && !strchr (IRC_NICK_VALID_CHARS, ptr_string[0])) + && !strchr (IRC_NICK_VALID_CHARS_RFC1459, ptr_string[0])) { return 0; } if ((utf8mapping == IRC_SERVER_UTF8MAPPING_RFC8265) - && strchr (IRC_NICK_INVALID_CHARS, ptr_string[0])) + && strchr (IRC_NICK_INVALID_CHARS_RFC8265, ptr_string[0])) { return 0; } diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index c25dfef5c..a861b005a 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -20,9 +20,9 @@ #ifndef WEECHAT_PLUGIN_IRC_NICK_H #define WEECHAT_PLUGIN_IRC_NICK_H -#define IRC_NICK_VALID_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHI" \ +#define IRC_NICK_VALID_CHARS_RFC1459 "abcdefghijklmnopqrstuvwxyzABCDEFGHI" \ "JKLMNOPQRSTUVWXYZ0123456789-[]\\`_^{|}" -#define IRC_NICK_INVALID_CHARS " ,:\n\r*?.!@" +#define IRC_NICK_INVALID_CHARS_RFC8265 " ,:\n\r*?.!@" /* nicklist group for nicks without prefix is "999|..." */ #define IRC_NICK_GROUP_OTHER_NUMBER 999 diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 4c4b985f3..8cac02a1f 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -282,6 +282,9 @@ enum t_irc_fingerprint_digest_algo IRC_FINGERPRINT_NUM_ALGOS, }; +extern char *irc_server_prefix_modes_default; +extern char *irc_server_prefix_chars_default; +extern char *irc_server_chanmodes_default; extern struct t_irc_server *irc_servers; extern const int gnutls_cert_type_prio[]; extern const int gnutls_prot_prio[]; -- cgit v1.2.3