From 3d87f28751db84fae47ec33925de050b7ad8ec11 Mon Sep 17 00:00:00 2001 From: codemastr Date: Mon, 8 Mar 2004 03:38:16 +0000 Subject: [PATCH] Added check to detect broad /spamfilter masks --- Changes | 3 +++ include/h.h | 2 +- src/modules/m_tkl.c | 2 +- src/s_conf.c | 4 ++-- src/s_misc.c | 10 +++++++++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 3cf620aeb..af66fdc76 100644 --- a/Changes +++ b/Changes @@ -3014,3 +3014,6 @@ seen. gmtime warning still there *** RC2fix release *** - spamfilter.conf: fixed fyle sig (was bad!), some minor updates to the rest, added mirc 6.12 exploit sig. Reported by PHANTOm. +- Added a check to try and prevent people from adding all-encompassing + regexp's in /spamfilter. Thanks to Ville Laurikari for coming up with the + method! diff --git a/include/h.h b/include/h.h index f8871e103..1f7d95b52 100644 --- a/include/h.h +++ b/include/h.h @@ -646,7 +646,7 @@ extern void extban_init(void); extern char *trim_str(char *str, int len); extern char *ban_realhost, *ban_virthost, *ban_ip; extern void join_channel(aChannel *chptr, aClient *cptr, aClient *sptr, int flags); -extern char *unreal_checkregex(char *s, int fastsupport); +extern char *unreal_checkregex(char *s, int fastsupport, int check_broadness); extern int banact_stringtoval(char *s); extern char *banact_valtostring(int val); extern int banact_chartoval(char c); diff --git a/src/modules/m_tkl.c b/src/modules/m_tkl.c index 1db3b18c9..14a15a55c 100644 --- a/src/modules/m_tkl.c +++ b/src/modules/m_tkl.c @@ -563,7 +563,7 @@ char targetbuf[64], actionbuf[2]; actionbuf[1] = '\0'; /* now check the regex... */ - p = unreal_checkregex(parv[6],0); + p = unreal_checkregex(parv[6],0,1); if (p) { sendto_one(sptr, ":%s NOTICE %s :Error in regex '%s': %s", diff --git a/src/s_conf.c b/src/s_conf.c index 390c44f8b..91e91fd82 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -4681,7 +4681,7 @@ int _test_badword(ConfigFile *conf, ConfigEntry *ce) { } else { - char *errbuf = unreal_checkregex(word->ce_vardata,1); + char *errbuf = unreal_checkregex(word->ce_vardata,1,0); if (errbuf) { config_error("%s:%i: badword::%s contains an invalid regex: %s", @@ -4836,7 +4836,7 @@ int _test_spamfilter(ConfigFile *conf, ConfigEntry *ce) errors++; } else if (cep->ce_vardata) { /* Check if it's a valid one */ - char *errbuf = unreal_checkregex(cep->ce_vardata,0); + char *errbuf = unreal_checkregex(cep->ce_vardata,0,0); if (errbuf) { config_error("%s:%i: spamfilter::regex contains an invalid regex: %s", diff --git a/src/s_misc.c b/src/s_misc.c index a3ed70c4c..8a05bf467 100644 --- a/src/s_misc.c +++ b/src/s_misc.c @@ -775,8 +775,10 @@ char *p; /** Checks if the specified regex (or fast badwords) is valid. * returns NULL in case of success [!], * pointer to buffer with error message otherwise + * if check_broadness is 1, the function will attempt to determine + * if the given regex string is too broad (i.e. matches everything) */ -char *unreal_checkregex(char *s, int fastsupport) +char *unreal_checkregex(char *s, int fastsupport, int check_broadness) { int errorcode, errorbufsize, regex=0; char *errtmp, *tmp; @@ -810,6 +812,12 @@ Ilovegotos: regfree(&expr); return errorbuf; } + if (check_broadness && !regexec(&expr, "", 0, NULL, 0)) + { + strncpyzt(errorbuf, "Regular expression is too broad", sizeof(errorbuf)); + regfree(&expr); + return errorbuf; + } regfree(&expr); } return NULL;