From c4245220deefc91ebcc41f264ec6e4dd7993f35b Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Wed, 13 May 2015 23:47:53 +0200 Subject: [PATCH] Fix MatchCaseInsensitive[List]](): lowercase string _and_ pattern Up to now, only the the string ("haystack") became lowercased and was the compared to the pattern ("needle") -- which failed, when the pattern itself wasn't all lowercase ... --- src/ngircd/match.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ngircd/match.c b/src/ngircd/match.c index 93ddc0bc..c1119a50 100644 --- a/src/ngircd/match.c +++ b/src/ngircd/match.c @@ -50,8 +50,10 @@ static int Matche_After_Star PARAMS(( const char *p, const char *t )); GLOBAL bool Match( const char *Pattern, const char *String ) { - if( Matche( Pattern, String ) == MATCH_VALID ) return true; - else return false; + if (Matche(Pattern, String) == MATCH_VALID) + return true; + else + return false; } /* Match */ /** @@ -64,10 +66,12 @@ Match( const char *Pattern, const char *String ) GLOBAL bool MatchCaseInsensitive(const char *Pattern, const char *String) { - char haystack[COMMAND_LEN]; + char needle[COMMAND_LEN], haystack[COMMAND_LEN]; + strlcpy(needle, Pattern, sizeof(needle)); strlcpy(haystack, String, sizeof(haystack)); - return Match(Pattern, ngt_LowerStr(haystack)); + + return Match(ngt_LowerStr(needle), ngt_LowerStr(haystack)); } /* MatchCaseInsensitive */ /** @@ -82,16 +86,14 @@ GLOBAL bool MatchCaseInsensitiveList(const char *Pattern, const char *String, const char *Separator) { - char tmp_pattern[COMMAND_LEN], haystack[COMMAND_LEN], *ptr; + char tmp_pattern[COMMAND_LEN], *ptr; strlcpy(tmp_pattern, Pattern, sizeof(tmp_pattern)); - strlcpy(haystack, String, sizeof(haystack)); - ngt_LowerStr(haystack); ptr = strtok(tmp_pattern, Separator); while (ptr) { ngt_TrimStr(ptr); - if (Match(ptr, haystack)) + if (MatchCaseInsensitive(ptr, String)) return true; ptr = strtok(NULL, Separator); } -- 2.39.2