From f11b1b963b303b2ec8fb0df201cfa70d92c05942 Mon Sep 17 00:00:00 2001 From: peavey Date: Tue, 26 Aug 2008 04:47:45 +0000 Subject: 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 --- src/wildcard.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') 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)) -- cgit v1.2.3