Skip to content

Commit c424522

Browse files
committed
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 ...
1 parent f8f7f83 commit c424522

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/ngircd/match.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ static int Matche_After_Star PARAMS(( const char *p, const char *t ));
5050
GLOBAL bool
5151
Match( const char *Pattern, const char *String )
5252
{
53-
if( Matche( Pattern, String ) == MATCH_VALID ) return true;
54-
else return false;
53+
if (Matche(Pattern, String) == MATCH_VALID)
54+
return true;
55+
else
56+
return false;
5557
} /* Match */
5658

5759
/**
@@ -64,10 +66,12 @@ Match( const char *Pattern, const char *String )
6466
GLOBAL bool
6567
MatchCaseInsensitive(const char *Pattern, const char *String)
6668
{
67-
char haystack[COMMAND_LEN];
69+
char needle[COMMAND_LEN], haystack[COMMAND_LEN];
6870

71+
strlcpy(needle, Pattern, sizeof(needle));
6972
strlcpy(haystack, String, sizeof(haystack));
70-
return Match(Pattern, ngt_LowerStr(haystack));
73+
74+
return Match(ngt_LowerStr(needle), ngt_LowerStr(haystack));
7175
} /* MatchCaseInsensitive */
7276

7377
/**
@@ -82,16 +86,14 @@ GLOBAL bool
8286
MatchCaseInsensitiveList(const char *Pattern, const char *String,
8387
const char *Separator)
8488
{
85-
char tmp_pattern[COMMAND_LEN], haystack[COMMAND_LEN], *ptr;
89+
char tmp_pattern[COMMAND_LEN], *ptr;
8690

8791
strlcpy(tmp_pattern, Pattern, sizeof(tmp_pattern));
88-
strlcpy(haystack, String, sizeof(haystack));
89-
ngt_LowerStr(haystack);
9092

9193
ptr = strtok(tmp_pattern, Separator);
9294
while (ptr) {
9395
ngt_TrimStr(ptr);
94-
if (Match(ptr, haystack))
96+
if (MatchCaseInsensitive(ptr, String))
9597
return true;
9698
ptr = strtok(NULL, Separator);
9799
}

0 commit comments

Comments
 (0)