]> jfr.im git - irc/unrealircd/unrealircd.git/commitdiff
Limit operclass name to a-zA-Z0-9_- and use the same validation in ~operclass extban.
authorBram Matthys <redacted>
Mon, 23 Oct 2023 07:48:40 +0000 (09:48 +0200)
committerBram Matthys <redacted>
Mon, 23 Oct 2023 07:51:01 +0000 (09:51 +0200)
This fixes the issue where +e/+I ~operclass:name gets cut off if the
name contains any digits.

Reported by BlackBishop in https://bugs.unrealircd.org/view.php?id=6353

Also, we previously allowed any characters in the operclass, which is not
a great idea.

include/h.h
include/struct.h
src/conf.c
src/misc.c
src/modules/extbans/operclass.c

index 828f37708a7ea4f23bc86a197e38566fc6421255..cd21f976dd579f49c6aa2c19bc9cd4ca4430983d 100644 (file)
@@ -1466,3 +1466,5 @@ extern const char *config_item_name(ConfigEntry *ce);
 extern int inchannel_compareflags(char symbol, const char *member_modes);
 extern int highest_channel_member_count(Client *client);
 extern MODVAR long long central_spamfilter_last_download;
+extern int valid_operclass_character(char c);
+extern int valid_operclass_name(const char *str);
index 180b911a06b9933ed9dfc8f1cb79bf88a46aae3b..ac17030276268ebd6fabcbfc746a2ce7d612496d 100644 (file)
@@ -191,6 +191,7 @@ typedef OperPermission (*OperClassEntryEvalCallback)(OperClassACLEntryVar* varia
 #define IDLEN          12
 #define SIDLEN         3
 #define SWHOISLEN      256
+#define OPERCLASSLEN   64
 #define UMODETABLESZ (sizeof(long) * 8)
 #define MAXCCUSERS             20 /* Maximum for set::anti-flood::max-concurrent-conversations */
 #define BATCHLEN       22
index 422a2615f1feb7f76c464a7afe6df2dae28e6ab2..7e4b981dac2f79c6b64beb99a2569946f8614d5f 100644 (file)
@@ -4085,7 +4085,15 @@ int      _test_operclass(ConfigFile *conf, ConfigEntry *ce)
        {
                config_error_noname(ce->file->filename, ce->line_number, "operclass");
                errors++;
+       } else
+       if (!valid_operclass_name(ce->value))
+       {
+               config_error("%s:%d: operclass name may only contain alphanumerical characters and "
+                            "characters _-",
+                            ce->file->filename, ce->line_number);
+               errors++;
        }
+
        for (cep = ce->items; cep; cep = cep->next)
        {
                if (!strcmp(cep->name, "parent"))
index 93b7021fb9d9675dbc461c296a94b8fc69391480..e0d98579ec849a7ab5cae5db1e28c9844be13105 100644 (file)
@@ -3107,3 +3107,25 @@ void download_complete_dontcare(const char *url, const char *file, const char *m
        }
 #endif
 }
+
+int valid_operclass_character(char c)
+{
+       /* allow alpha, numeric, -, _ */
+       if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_", c))
+               return 0;
+       return 1;
+}
+
+int valid_operclass_name(const char *str)
+{
+       const char *p;
+
+       if (strlen(str) > OPERCLASSLEN)
+               return 0;
+
+       for (p = str; *p; p++)
+               if (!valid_operclass_character(*p))
+                       return 0;
+
+       return 1;
+}
index 5b6bc2a51e2e21c45c0e4cb34a6bd0166626633d..8d07b7fbf8e8e9c0f9d0f6e3cdad9d355665dd08 100644 (file)
@@ -68,8 +68,6 @@ MOD_UNLOAD()
 }
 
 
-#define OPERCLASSLEN 64
-
 const char *extban_operclass_conv_param(BanContext *b, Extban *extban)
 {
        static char retbuf[OPERCLASSLEN + 4];
@@ -77,10 +75,15 @@ const char *extban_operclass_conv_param(BanContext *b, Extban *extban)
 
        strlcpy(retbuf, b->banstr, sizeof(retbuf));
 
-       /* allow alpha, numeric, -, _, * and ? wildcards */
+       /* cut off at first invalid character (.. but allow wildcards) */
        for (p = retbuf; *p; p++)
-               if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_?*", *p))
+       {
+               if (!valid_operclass_character(*p) && !strchr("*?", *p))
+               {
                        *p = '\0';
+                       break;
+               }
+       }
 
        if (retbuf[3] == '\0')
                return NULL; /* just "~O:" is invalid */