diff options
author | Jakub Jelen <jjelen@redhat.com> | 2019-10-29 14:02:23 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-12-09 16:08:03 +0100 |
commit | cf0beff987cc01e4ab0dd66cb1931c49511956c9 (patch) | |
tree | 6e719316bd62bcec422e04f74ac6e459bd3bb76b /src | |
parent | 178b53f92434b214e3068e33811690b1227b2e15 (diff) | |
download | libssh-cf0beff987cc01e4ab0dd66cb1931c49511956c9.tar.gz libssh-cf0beff987cc01e4ab0dd66cb1931c49511956c9.tar.xz libssh-cf0beff987cc01e4ab0dd66cb1931c49511956c9.zip |
match: Avoid recursion with many asterisks in pattern
Partially fixes T186
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/match.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/match.c b/src/match.c index 06587b92..5c85c7b0 100644 --- a/src/match.c +++ b/src/match.c @@ -38,6 +38,7 @@ #include "config.h" #include <ctype.h> +#include <stdbool.h> #include <sys/types.h> #include "libssh/priv.h" @@ -46,7 +47,9 @@ * Returns true if the given string matches the pattern (which may contain ? * and * as wildcards), and zero if it does not match. */ -static int match_pattern(const char *s, const char *pattern) { +static int match_pattern(const char *s, const char *pattern) +{ + bool had_asterisk = false; if (s == NULL || pattern == NULL) { return 0; } @@ -57,16 +60,19 @@ static int match_pattern(const char *s, const char *pattern) { return (*s == '\0'); } - if (*pattern == '*') { + while (*pattern == '*') { /* Skip the asterisk. */ + had_asterisk = true; pattern++; + } + if (had_asterisk) { /* If at end of pattern, accept immediately. */ if (!*pattern) return 1; /* If next character in pattern is known, optimize. */ - if (*pattern != '?' && *pattern != '*') { + if (*pattern != '?') { /* * Look instances of the next character in * pattern, and try to match starting from |