summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2008-08-26 04:47:45 +0000
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2008-08-26 04:47:45 +0000
commitf11b1b963b303b2ec8fb0df201cfa70d92c05942 (patch)
treec71201ab2ed85db30284a7c79dc54b2041813be7 /src
parent4b8661270d999e302d183de5184c8cafd574aa62 (diff)
Iteration 5 of wildcard matching. Fixes broken matching for certain conditions reported by MacGyver.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10302 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/wildcard.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index 074a91eed..2a2c6ad52 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -28,11 +28,16 @@
* ZNC's, thought to be faster than ours, but it turned out that we could do better ;-)
* Iteration 4)
* Largely from work by peavey and myself (w00t) :)
- *
+ * Iteration 5)
+ * peavey: Fix glob scan similar to 1.1, but scan ahead on glob in inner loop to retain speedup
+ * this fixes another case which we forgot to test. Add early return for obvious fail condition.
*/
static bool match_internal(const unsigned char *string, const unsigned char *wild, unsigned const char *map)
{
- const unsigned char* s;
+ const unsigned char *s, *m; m = wild;
+
+ if (*string && !*wild)
+ return false;
if (!map)
map = lowermap;
@@ -44,6 +49,8 @@ static bool match_internal(const unsigned char *string, const unsigned char *wil
while (*wild && *wild == '*')
wild++;
+ m = wild;
+
if (!*wild)
return true;
else if (*wild != '?')
@@ -57,19 +64,17 @@ static bool match_internal(const unsigned char *string, const unsigned char *wil
if (*(wild+1) || !*(s+1))
{
wild++;
- break;
}
+ break;
}
s++;
}
}
}
- else if ( (map[*wild] != map[*string]) && (*wild != '?') )
- {
- return false;
- }
- else
+ else if ( (map[*wild] == map[*string]) || (*wild == '?') )
wild++;
+ else
+ wild = m;
string++;
}
@@ -94,7 +99,6 @@ CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned con
return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
}
-
CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
{
if (irc::sockets::MatchCIDR(str, mask, true))