diff mbox

[linux-cifs-client,4/5] cifs: Make cifs_readdir use the helpers

Message ID 49E89D8C.8070002@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Suresh Jayaraman April 17, 2009, 3:17 p.m. UTC
We need to get the string from current_entry before calling
UniStrnlenBytes()

Signed-off-by: Suresh Jayaraman <sjayaraman@suse.de>
---
 fs/cifs/readdir.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

Comments

Jeff Layton April 17, 2009, 7:42 p.m. UTC | #1
On Fri, 17 Apr 2009 20:47:32 +0530
Suresh Jayaraman <sjayaraman@suse.de> wrote:

> We need to get the string from current_entry before calling
> UniStrnlenBytes()
> 
> Signed-off-by: Suresh Jayaraman <sjayaraman@suse.de>
> ---
>  fs/cifs/readdir.c |   16 +++++++++-------
>  1 files changed, 9 insertions(+), 7 deletions(-)
> 
> Index: cifs-2.6.git/fs/cifs/readdir.c
> ===================================================================
> --- cifs-2.6.git.orig/fs/cifs/readdir.c
> +++ cifs-2.6.git/fs/cifs/readdir.c
> @@ -995,8 +995,10 @@ int cifs_readdir(struct file *file, void
>  	char *current_entry;
>  	int num_to_fill = 0;
>  	char *tmp_buf = NULL;
> -	char *end_of_smb;
> -	int max_len;
> +	char *end_of_smb, *filename;
> +	int max_len, nchars;
> +	size_t nbytes;
> +	FILE_UNIX_INFO *punix_info;
>  
>  	xid = GetXid();
>  
> @@ -1070,11 +1072,12 @@ int cifs_readdir(struct file *file, void
>  				cifsFile->srch_inf.ntwrk_buf_start);
>  		end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
>  
> -		/* To be safe - for UCS to UTF-8 with strings loaded
> -		with the rare long characters alloc more to account for
> -		such multibyte target UTF-8 characters. cifs_unicode.c,
> -		which actually does the conversion, has the same limit */
> -		tmp_buf = kmalloc((2 * NAME_MAX) + 4, GFP_KERNEL);
> +		/* compute the actual length in bytes required and use it */
> +		punix_info = (FILE_UNIX_INFO *)current_entry;
> +		filename = &punix_info->FileName[0];
> +		nbytes = UniStrnlenBytes((wchar_t *)filename, 2*NAME_MAX,
> +				&nchars, cifs_sb->local_nls);
> +		tmp_buf = kmalloc(nbytes + 2, GFP_KERNEL);

You're sizing the buffer by the size of the entry that started the
search. I don't think you can reasonably predict how big a buffer
you'll need here. I think the best you can do is just make tmp_buf get
a buffer that's the max you could possibly need -- (NAME_MAX * 4) + 2.

>  		for (i = 0; (i < num_to_fill) && (rc == 0); i++) {
>  			if (current_entry == NULL) {
>  				/* evaluate whether this case is an error */
>
diff mbox

Patch

Index: cifs-2.6.git/fs/cifs/readdir.c
===================================================================
--- cifs-2.6.git.orig/fs/cifs/readdir.c
+++ cifs-2.6.git/fs/cifs/readdir.c
@@ -995,8 +995,10 @@  int cifs_readdir(struct file *file, void
 	char *current_entry;
 	int num_to_fill = 0;
 	char *tmp_buf = NULL;
-	char *end_of_smb;
-	int max_len;
+	char *end_of_smb, *filename;
+	int max_len, nchars;
+	size_t nbytes;
+	FILE_UNIX_INFO *punix_info;
 
 	xid = GetXid();
 
@@ -1070,11 +1072,12 @@  int cifs_readdir(struct file *file, void
 				cifsFile->srch_inf.ntwrk_buf_start);
 		end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
 
-		/* To be safe - for UCS to UTF-8 with strings loaded
-		with the rare long characters alloc more to account for
-		such multibyte target UTF-8 characters. cifs_unicode.c,
-		which actually does the conversion, has the same limit */
-		tmp_buf = kmalloc((2 * NAME_MAX) + 4, GFP_KERNEL);
+		/* compute the actual length in bytes required and use it */
+		punix_info = (FILE_UNIX_INFO *)current_entry;
+		filename = &punix_info->FileName[0];
+		nbytes = UniStrnlenBytes((wchar_t *)filename, 2*NAME_MAX,
+				&nchars, cifs_sb->local_nls);
+		tmp_buf = kmalloc(nbytes + 2, GFP_KERNEL);
 		for (i = 0; (i < num_to_fill) && (rc == 0); i++) {
 			if (current_entry == NULL) {
 				/* evaluate whether this case is an error */