mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
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>
This commit is contained in:
parent
548e9ad317
commit
b24c933580
4 changed files with 9 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -11,7 +11,7 @@ struct nls_table;
|
|||
struct kstat;
|
||||
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);
|
||||
|
||||
|
|
|
@ -3837,7 +3837,7 @@ static int __query_dir(struct dir_context *ctx,
|
|||
return 0;
|
||||
if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name))
|
||||
return 0;
|
||||
if (!match_pattern(name, priv->search_pattern))
|
||||
if (!match_pattern(name, namlen, priv->search_pattern))
|
||||
return 0;
|
||||
|
||||
d_info->name = name;
|
||||
|
|
|
@ -294,7 +294,8 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work,
|
|||
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;
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue