summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wobst <wobst.michael@web.de>2022-01-09 16:25:09 +0100
committerGitHub <noreply@github.com>2022-01-09 15:25:09 +0000
commitc38106211ce6d20d17c2c49286a2c0b5f3a6229b (patch)
tree256108a010a9cd306a3839c042307740866976ce
parentb8bcad048e7a87594e15bb0b42317fb3a4f64b83 (diff)
Adjust IsIdentValid test to comply with upcoming ircd-hybrid release (#272).
hybrid.cpp: adjust IsIdentValid test to comply with upcoming ircd-hybrid where user names may only consist of [A-Za-z0-9._-] and may not begin with '.', '-', or '_'. As a side effect this fixes an issue where currently it is possible to introduce bots whose user name starts with (non-alnum) characters considered invalid for ircd-hybrid leading to a services shutdown due to a nick introduction/kill loop.
-rw-r--r--modules/protocol/hybrid.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp
index 640408052..3a1b6ce59 100644
--- a/modules/protocol/hybrid.cpp
+++ b/modules/protocol/hybrid.cpp
@@ -280,16 +280,30 @@ class HybridProto : public IRCDProto
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
- Anope::string chars = "~}|{ `_^]\\[ .-$";
+ /*
+ * If the user name begins with a tilde (~), make sure there is at least
+ * one succeeding character.
+ */
+ unsigned i = ident[0] == '~';
+ if (i >= ident.length())
+ return false;
+
+ /* User names may not start with a '-', '_', or '.'. */
+ const char &a = ident[i];
+ if (a == '-' || a == '_' || a == '.')
+ return false;
- for (unsigned i = 0; i < ident.length(); ++i)
+ for (i = 0; i < ident.length(); ++i)
{
const char &c = ident[i];
- if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
+ /* A tilde can only be used as the first character of a user name. */
+ if (c == '~' && i == 0)
continue;
- if (chars.find(c) != Anope::string::npos)
+ if ((c >= 'A' && c <= 'Z') ||
+ (c >= 'a' && c <= 'z') ||
+ (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.')
continue;
return false;