Commit b24c9335 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French

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: default avatarMarios Makassikis <mmakassikis@freebox.fr>
Signed-off-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 548e9ad3
...@@ -22,20 +22,22 @@ ...@@ -22,20 +22,22 @@
* TODO : implement consideration about DOS_DOT, DOS_QM and DOS_STAR * TODO : implement consideration about DOS_DOT, DOS_QM and DOS_STAR
* *
* @string: string to compare with a pattern * @string: string to compare with a pattern
* @len: string length
* @pattern: pattern string which might include wildcard '*' and '?' * @pattern: pattern string which might include wildcard '*' and '?'
* *
* Return: 0 if pattern matched with the string, otherwise non zero value * 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 *s = str;
const char *p = pattern; const char *p = pattern;
bool star = false; bool star = false;
while (*s) { while (*s && len) {
switch (*p) { switch (*p) {
case '?': case '?':
s++; s++;
len--;
p++; p++;
break; break;
case '*': case '*':
...@@ -48,6 +50,7 @@ int match_pattern(const char *str, const char *pattern) ...@@ -48,6 +50,7 @@ int match_pattern(const char *str, const char *pattern)
default: default:
if (tolower(*s) == tolower(*p)) { if (tolower(*s) == tolower(*p)) {
s++; s++;
len--;
p++; p++;
} else { } else {
if (!star) if (!star)
......
...@@ -11,7 +11,7 @@ struct nls_table; ...@@ -11,7 +11,7 @@ struct nls_table;
struct kstat; struct kstat;
struct ksmbd_file; struct ksmbd_file;
int match_pattern(const char *str, const char *pattern); int match_pattern(const char *str, size_t len, const char *pattern);
int ksmbd_validate_filename(char *filename); int ksmbd_validate_filename(char *filename);
......
...@@ -3837,7 +3837,7 @@ static int __query_dir(struct dir_context *ctx, ...@@ -3837,7 +3837,7 @@ static int __query_dir(struct dir_context *ctx,
return 0; return 0;
if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name)) if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name))
return 0; return 0;
if (!match_pattern(name, priv->search_pattern)) if (!match_pattern(name, namlen, priv->search_pattern))
return 0; return 0;
d_info->name = name; d_info->name = name;
......
...@@ -294,7 +294,8 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, ...@@ -294,7 +294,8 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work,
d_info->name_len = 2; d_info->name_len = 2;
} }
if (!match_pattern(d_info->name, search_pattern)) { if (!match_pattern(d_info->name, d_info->name_len,
search_pattern)) {
dir->dot_dotdot[i] = 1; dir->dot_dotdot[i] = 1;
continue; continue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment