1
1

match: Optimize pattern matching even more

The adjacent question marks and asterisks can be simplified to single
wildcard so there is no need to excersise all the recursive pattern
matching.

These inputs were generated by oss-fuzz and probably caused also the
previously reported timeouts.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Jakub Jelen 2022-02-09 22:17:47 +01:00
родитель 44665f33a4
Коммит d171a6e444

Просмотреть файл

@ -63,9 +63,11 @@ static int match_pattern(const char *s, const char *pattern, size_t limit)
return (*s == '\0');
}
while (*pattern == '*') {
/* Skip all the asterisks. */
had_asterisk = true;
/* Skip all the asterisks and adjacent question marks */
while (*pattern == '*' || (had_asterisk && *pattern == '?')) {
if (*pattern == '*') {
had_asterisk = true;
}
pattern++;
}