diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-08-17 15:33:13 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-08-17 15:33:13 +0000 |
commit | dd6464f8f64ba25f428a4d81a592a0223d45ca53 (patch) | |
tree | 86c4ca1ac7272b6ec00cd37a3e9d2245aedca629 /src/wildcard.cpp | |
parent | 25ab84013a123de5ee05058b0b2bc37767a015c9 (diff) |
Fix missing bounds checks in wildcard.cpp causing crash in bug #590 and related
Add test cases for wildcards to pick this up in future regression testing plus a bunch of other edge cases
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10147 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/wildcard.cpp')
-rw-r--r-- | src/wildcard.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/wildcard.cpp b/src/wildcard.cpp index ccd2e9ec1..b230ab147 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -41,18 +41,21 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask) while ((string != str.end()) && (wild != mask.end()) && (*wild != '*')) { if ((*wild != *string) && (*wild != '?')) - return 0; + return false; wild++; string++; } + if (wild == mask.end() && string != str.end()) + return false; + while (string != str.end()) { if (wild != mask.end() && *wild == '*') { if (++wild == mask.end()) - return 1; + return true; mp = wild; cp = string; @@ -95,18 +98,25 @@ CoreExport bool match(const std::string &str, const std::string &mask) while ((string != str.end()) && (wild != mask.end()) && (*wild != '*')) { if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?')) - return 0; + return false; wild++; string++; + //printf("Iterate first loop\n"); } + if (wild == mask.end() && string != str.end()) + return false; + while (string != str.end()) { + //printf("outer\n %c", *string); if (wild != mask.end() && *wild == '*') { + + //printf("inner %c\n", *wild); if (++wild == mask.end()) - return 1; + return true; mp = wild; cp = string; @@ -118,8 +128,11 @@ CoreExport bool match(const std::string &str, const std::string &mask) else if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))) { - wild++; - string++; + if (wild != mask.end()) + wild++; + + if (string != str.end()) + string++; } else { |