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

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
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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;
+2 −1
Original line number Diff line number Diff line
@@ -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;
			}