[linux-cifs-client] [PATCH] cifs: Fix insufficient memory
allocation for nativeFileSystem field
Jeff Layton
jlayton at redhat.com
Thu Apr 9 11:55:30 GMT 2009
On Tue, 07 Apr 2009 18:45:46 +0530
Suresh Jayaraman <sjayaraman at suse.de> wrote:
> Do we still need this conversion again?
>
I know this isn't a "real" patch submission yet, but some comments
below...
>
> diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
> index 14eb9a2..0396bdc 100644
> --- a/fs/cifs/cifs_unicode.h
> +++ b/fs/cifs/cifs_unicode.h
> @@ -159,6 +159,23 @@ UniStrnlen(const wchar_t *ucs1, int maxlen)
> }
>
> /*
> + * UniStrnlenBytes: Return the length in bytes of a UTF-8 string
> + */
> +static inline size_t
> +UniStrnlenBytes(const unsigned char *str, int maxlen)
> +{
> + size_t nbytes = 0;
> + wchar_t *uni;
^^^^^
I think you need to allocate actual storage for the character here.
> +
> + while (*str++) {
> + /* convert each char, find its length and add to nbytes */
> + if (char2uni(str, maxlen, uni) > 0)
> + nbytes += strnlen(uni, NLS_MAX_CHARSET_SIZE);
"uni" is a ptr to a wchar_t, but you're treating it as a string.
There's no guarantee that it'll be null-terminated. I might be
mistaken, but doesn't char2uni return the length of the converted
character in bytes? Tallying up the return from those is probably
the thing to do.
> + }
> + return nbytes;
> +}
> +
> +/*
--
Jeff Layton <jlayton at redhat.com>
More information about the linux-cifs-client
mailing list