]> jfr.im git - irc/DALnet/bahamut.git/commitdiff
Fix our incorrect handling of IRC color code sequences, which follow the pattern...
authorRyan Smith <redacted>
Wed, 4 Sep 2019 01:49:08 +0000 (21:49 -0400)
committerRyan Smith <redacted>
Wed, 4 Sep 2019 01:49:08 +0000 (21:49 -0400)
src/spamfilter.c

index 61ebc4d55953881dbd372e3648d0f7acec3f9b8a..7c7d408015d68b3414fc261b5aed9f1726a548e7 100644 (file)
@@ -488,16 +488,33 @@ void stripcolors(char new[512], char *org)
 {
     int len = 0;
 
-    for(; (*org && len<512); org++)
+    for(; (*org && len < 512); org++)
     {
-        if(*org=='\003')
+        if(*org == '\003')
         {
+            // Color codes: 1-2 digits, then optionally followed by a comma and an additional 1-2 digits
             org++;
-            while(IsDigit(*org) || *org==',')
+            if(*org && IsDigit(*org))
+            {
                 org++;
+                if(*org && IsDigit(*org))
+                {
+                    org++;
+                }
+                if(*org && *org == ',' && IsDigit(*(org + 1)))
+                {
+                    org = org + 2;
+                    if(*org && IsDigit(*org))
+                    {
+                        org++;
+                    }
+                }
+            }
         }
-        if(*org<32)
+        if(*org < 32)
+        {
             continue;
+        }
         new[len++] = *org;
     }
     new[len] = '\0';
@@ -511,11 +528,26 @@ void stripall(char new[512], char *org)
 
     for(; (*org && len<512); org++)
     {
-        if(*org=='\003')
+        if(*org == '\003')
         {
+            // Color codes: 1-2 digits, then optionally followed by a comma and an additional 1-2 digits
             org++;
-            while(IsDigit(*org) || *org==',')
+            if(*org && IsDigit(*org))
+            {
                 org++;
+                if(*org && IsDigit(*org))
+                {
+                    org++;
+                }
+                if(*org && *org == ',' && IsDigit(*(org + 1)))
+                {
+                    org = org + 2;
+                    if(*org && IsDigit(*org))
+                    {
+                        org++;
+                    }
+                }
+            }
         }
         if(!fstripall(*org))
             continue;