View | Details | Raw Unified | Return to bug 2591 | Differences between
and this patch

Collapse All | Expand All

(-)match.c (-7 / +19 lines)
Lines 119-128 Link Here
119
match_pattern_list(const char *string, const char *pattern, int dolower)
119
match_pattern_list(const char *string, const char *pattern, int dolower)
120
{
120
{
121
	char sub[1024];
121
	char sub[1024];
122
	char *low_string = NULL;
122
	int negated;
123
	int negated;
123
	int got_positive;
124
	int got_positive;
124
	u_int i, subi, len = strlen(pattern);
125
	u_int i, subi, len = strlen(pattern);
125
126
127
	if (dolower) {
128
		low_string = xmalloc(strlen(string) + 1);
129
		for (i = 0; string[i]; ++i)
130
			low_string[i] = tolower(string[i]);
131
		low_string[i] = '\0';
132
	}
133
126
	got_positive = 0;
134
	got_positive = 0;
127
	for (i = 0; i < len;) {
135
	for (i = 0; i < len;) {
128
		/* Check if the subpattern is negated. */
136
		/* Check if the subpattern is negated. */
Lines 142-149 Link Here
142
			sub[subi] = dolower && isupper((u_char)pattern[i]) ?
150
			sub[subi] = dolower && isupper((u_char)pattern[i]) ?
143
			    tolower((u_char)pattern[i]) : pattern[i];
151
			    tolower((u_char)pattern[i]) : pattern[i];
144
		/* If subpattern too long, return failure (no match). */
152
		/* If subpattern too long, return failure (no match). */
145
		if (subi >= sizeof(sub) - 1)
153
		if (subi >= sizeof(sub) - 1) {
154
			free(low_string);
146
			return 0;
155
			return 0;
156
		}
147
157
148
		/* If the subpattern was terminated by a comma, skip the comma. */
158
		/* If the subpattern was terminated by a comma, skip the comma. */
149
		if (i < len && pattern[i] == ',')
159
		if (i < len && pattern[i] == ',')
Lines 153-170 Link Here
153
		sub[subi] = '\0';
163
		sub[subi] = '\0';
154
164
155
		/* Try to match the subpattern against the string. */
165
		/* Try to match the subpattern against the string. */
156
		if (match_pattern(string, sub)) {
166
		if (match_pattern((dolower ? low_string : string), sub)) {
157
			if (negated)
167
			if (negated) {
158
				return -1;		/* Negative */
168
				got_positive = -1;		/* Negative */
159
			else
169
				break;
170
			} else
160
				got_positive = 1;	/* Positive */
171
				got_positive = 1;	/* Positive */
161
		}
172
		}
162
	}
173
	}
163
174
164
	/*
175
	/*
165
	 * Return success if got a positive match.  If there was a negative
176
	 * Return success if there was a positive match;
166
	 * match, we have already returned -1 and never get here.
177
	 * return -1 if there was a negative match.
167
	 */
178
	 */
179
	free(low_string);
168
	return got_positive;
180
	return got_positive;
169
}
181
}
170
182

Return to bug 2591