From 3618b2a2faccd634e0485c09eee92b40b42eebf3 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 13 Apr 2003 19:04:46 +0000 Subject: [PATCH] - badword::action::block should now be ok --- Changes | 1 + src/badwords.c | 40 +++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Changes b/Changes index 38213583e..957a043b7 100644 --- a/Changes +++ b/Changes @@ -2052,3 +2052,4 @@ seen. gmtime warning still there AngryWolf - Made it so you can use a ~ as the first character of an ident with /chgident (#0000765) reported by AngryWolf +- badword::action::block should now be ok diff --git a/src/badwords.c b/src/badwords.c index 973a9b8e0..7ce45daff 100644 --- a/src/badwords.c +++ b/src/badwords.c @@ -52,20 +52,30 @@ int hlength = strlen (haystack); } inline int fast_badword_match(ConfigItem_badword *badword, char *line) { - char *temp; - int ret; - if (!(badword->type & (BADW_TYPE_FAST_R|BADW_TYPE_FAST_L))) - return (our_strcasestr(line, badword->word) ? 0 : 1); - /* This can be made faster, but for now I just want it to work */ - temp = MyMallocEx(strlen(badword->word)+3); - if (badword->type & BADW_TYPE_FAST_L) - strcat(temp, "*"); - strcat(temp, badword->word); - if (badword->type & BADW_TYPE_FAST_R) - strcat(temp, "*"); - ret = match(temp, line); - free(temp); - return ret; + char *p; + int ret, bwlen = strlen(badword->word); + if ((badword->type & BADW_TYPE_FAST_L) && (badword->type & BADW_TYPE_FAST_R)) + return (our_strcasestr(line, badword->word) ? 1 : 0); + + p = line; + while((p = our_strcasestr(p, badword->word))) + { + if (!(badword->type & BADW_TYPE_FAST_L)) + { + if ((p != line) && isalnum(*(p - 1))) /* aaBLA but no *BLA */ + goto next; + } + if (!(badword->type & BADW_TYPE_FAST_R)) + { + if (isalnum(*(p + bwlen))) /* BLAaa but no BLA* */ + goto next; + } + /* Looks like it matched */ + return 1; +next: + p += bwlen; + } + return 0; } /* fast_badword_replace: * a fast replace routine written by Syzop used for replacing badwords. @@ -199,7 +209,7 @@ char *stripbadwords(char *str, ConfigItem_badword *start_bw, int *blocked) { if (this_word->action == BADWORD_BLOCK) { - if (!fast_badword_match(this_word, cleanstr)) + if (fast_badword_match(this_word, cleanstr)) { *blocked = 1; return NULL;