diff options
author | Namjae Jeon <namjae.jeon@samsung.com> | 2021-03-21 17:32:19 +0900 |
---|---|---|
committer | Steve French <stfrench@microsoft.com> | 2021-05-10 19:15:24 -0500 |
commit | b24c93358035e3c20630a45c0bcdbb45aad9707d (patch) | |
tree | f8749a6c40449914f89667abb0e169b3a9153fd0 /fs/cifsd/misc.c | |
parent | 548e9ad317393b0439081454d2110f519431d5ef (diff) |
cifsd: Pass string length parameter to match_pattern()
When iterating through a directory, a file's name may not be
null-terminated (depending on the underlying filesystem implementation).
Modify match_pattern to take the string's length into account when matching
it against the request pattern.
Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifsd/misc.c')
-rw-r--r-- | fs/cifsd/misc.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/cifsd/misc.c b/fs/cifsd/misc.c index 68983b08d519..189b90414976 100644 --- a/fs/cifsd/misc.c +++ b/fs/cifsd/misc.c @@ -22,20 +22,22 @@ * TODO : implement consideration about DOS_DOT, DOS_QM and DOS_STAR * * @string: string to compare with a pattern + * @len: string length * @pattern: pattern string which might include wildcard '*' and '?' * * Return: 0 if pattern matched with the string, otherwise non zero value */ -int match_pattern(const char *str, const char *pattern) +int match_pattern(const char *str, size_t len, const char *pattern) { const char *s = str; const char *p = pattern; bool star = false; - while (*s) { + while (*s && len) { switch (*p) { case '?': s++; + len--; p++; break; case '*': @@ -48,6 +50,7 @@ int match_pattern(const char *str, const char *pattern) default: if (tolower(*s) == tolower(*p)) { s++; + len--; p++; } else { if (!star) |