]> jfr.im git - irc/atheme/atheme.git/commitdiff
libathemecore/phandler.c: is_valid_nick: check nickname length too
authorAaron Jones <redacted>
Sun, 11 Jul 2021 10:53:07 +0000 (10:53 +0000)
committerAaron Jones <redacted>
Sun, 11 Jul 2021 11:13:26 +0000 (11:13 +0000)
Also document more thoroughly why nicknames cannot begin with a digit
or a hyphen.

libathemecore/phandler.c

index fa8356df344cabe004895d2fb63bf3c77c6ad3ea..7defe3ad0e6f932bd1e260f60ec03fd1ff1a1663 100644 (file)
@@ -394,15 +394,18 @@ generic_next_matching_host_chanacs(struct mychan *mc, struct user *u, mowgli_nod
 bool
 generic_is_valid_nick(const char *nick)
 {
-       const char *iter = nick;
-
-       /* nicknames may not normally begin with a number, due to UID collision */
-       if (IsDigit(*iter))
+       /* nicknames may not begin with a digit or a hyphen; the former because they are usually
+        * reserved for UIDs and thus may collide, and both because it is specified as such in
+        * <https://datatracker.ietf.org/doc/html/rfc2812#section-2.3.1>
+        */
+       if (IsDigit(*nick) || *nick == '-')
                return false;
-       if (*iter == '-')
+
+       // nicknames cannot be longer than we support
+       if (strlen(nick) > NICKLEN)
                return false;
 
-       for (; *iter != '\0'; iter++)
+       for (const char *iter = nick; *iter != '\0'; iter++)
        {
                if (!IsNickChar(*iter))
                        return false;