]> jfr.im git - irc/rizon/plexus4.git/commitdiff
Fix sub-minute d/k lines from being permanent
authorAdam <redacted>
Fri, 9 Apr 2021 15:05:29 +0000 (11:05 -0400)
committerAdam <redacted>
Fri, 9 Apr 2021 15:07:12 +0000 (11:07 -0400)
If a server sends a d/kline with an expiry time less than 60,
valid_tkline would return 0 due to the conversion from seconds to
minutes in order to compare with MAX_TDKLINE_TIME. Additionally allow
opers to pass 0 as an expiry to KLINE/DLINE and treat it as permanent,
instead of 1 minute.

include/conf.h
modules/m_dline.c
modules/m_kline.c
src/conf.c

index 536c8db62f2e9195c9c66824c2363ab416ac6f50..3263f94d962cb9ff9043489acbb22852c4273979 100644 (file)
@@ -496,7 +496,7 @@ extern int valid_comment(struct Client *, char *, int);
 
 #define TK_SECONDS 0
 #define TK_MINUTES 1
-extern time_t valid_tkline(const char *, const int);
+extern bool valid_tkline(const char *, const int, time_t *);
 extern int match_conf_password(const char *, const struct MaskItem *);
 
 #define CLEANUP_TKLINES_TIME 60
index 9c7bbc993399b1397476e401c8e86a1e5f9bd429..0f43fd4a0d77963bba9faf08485935b9993482d9 100644 (file)
@@ -270,7 +270,7 @@ do_dline(struct Client *source_p, char *dtime, char *dhost, char *dreason)
   int bits = 0, aftype = 0, t = 0;
   char hostip[HOSTIPLEN + 1];
 
-  tkline_time = valid_tkline(dtime, TK_SECONDS);
+  valid_tkline(dtime, TK_SECONDS, &tkline_time);
   dlhost = dhost;
   reason = dreason;
 
index 9b593dbaf92f5fceb258ed93bf8386eb4389fb61..457e934df2ab5559f37ee5ed0f0c4c31f19b3288 100644 (file)
@@ -311,7 +311,7 @@ me_kline(struct Client *client_p, struct Client *source_p,
          int parc, char *parv[])
 {
   struct MaskItem *conf = NULL;
-  int tkline_time = 0;
+  time_t tkline_time = 0;
   char *kuser, *khost, *kreason;
 
   if (parc != 6 || EmptyString(parv[5]))
@@ -320,7 +320,7 @@ me_kline(struct Client *client_p, struct Client *source_p,
   if (match(parv[1], me.name))
     return;
 
-  tkline_time = valid_tkline(parv[2], TK_SECONDS);
+  valid_tkline(parv[2], TK_SECONDS, &tkline_time);
   kuser = parv[3];
   khost = parv[4];
   kreason = parv[5];
index 279bf2b7f0c7c8db070ec3de9e9abdfb9cdb0e67..b8ffac6abc50b9361b5eef3aeadeafd32b15bb2d 100644 (file)
@@ -1876,13 +1876,13 @@ conf_error_report(const char *msg)
  *
  * inputs       - pointer to ascii string to check
  *              - whether the specified time is in seconds or minutes
- * output       - -1 not enough parameters
- *              - 0 if not an integer number, else the number
+ *              - pointer to the parsed value in seconds
+ * output       - true if the data passed is a valid time, otherwise false
  * side effects - none
  * Originally written by Dianora (Diane, db@db.net)
  */
-time_t
-valid_tkline(const char *data, const int minutes)
+bool
+valid_tkline(const char *data, const int minutes, time_t *out)
 {
   const unsigned char *p = (const unsigned char *)data;
   unsigned char tmpch = '\0';
@@ -1891,33 +1891,22 @@ valid_tkline(const char *data, const int minutes)
   while ((tmpch = *p++))
   {
     if (!IsDigit(tmpch))
-      return 0;
+      return false;
 
     result *= 10;
     result += (tmpch & 0xF);
   }
 
-  /*
-   * In the degenerate case where oper does a /quote kline 0 user@host :reason
-   * i.e. they specifically use 0, I am going to return 1 instead
-   * as a return value of non-zero is used to flag it as a temporary kline
-   */
-  if (result == 0)
-    result = 1;
-
-  /*
-   * If the incoming time is in seconds convert it to minutes for the purpose
-   * of this calculation
-   */
-  if (!minutes)
-    result = result / 60;
+  // Convert to seconds
+  if (minutes)
+    result *= 60;
 
-  if (result > MAX_TDKLINE_TIME)
-    result = MAX_TDKLINE_TIME;
+  // MAX_TDKLINE_TIME is in minutes, so convert to seconds
+  if (result > MAX_TDKLINE_TIME * 60)
+    result = MAX_TDKLINE_TIME * 60;
 
-  result = result * 60;  /* turn it into seconds */
-
-  return result;
+  *out = result;
+  return true;
 }
 
 /* valid_wild_card_simple()
@@ -2050,7 +2039,7 @@ parse_aline(const char *cmd, struct Client *source_p,
             int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
             char **target_server, char **reason)
 {
-  int found_tkline_time=0;
+  time_t parsed_tkline_time;
   static char def_reason[] = CONF_NOREASON;
   static char user[USERLEN*4+1];
   static char host[HOSTLEN*4+1];
@@ -2058,15 +2047,13 @@ parse_aline(const char *cmd, struct Client *source_p,
   parv++;
   parc--;
 
-  found_tkline_time = valid_tkline(*parv, TK_MINUTES);
-
-  if (found_tkline_time != 0)
+  if (valid_tkline(*parv, TK_MINUTES, &parsed_tkline_time))
   {
     parv++;
     parc--;
 
     if (tkline_time != NULL)
-      *tkline_time = found_tkline_time;
+      *tkline_time = parsed_tkline_time;
     else
     {
       sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",