[linux-cifs-client] [PATCH] cifs: Fix insufficient
memory allocation for nativeFileSystem field
Suresh Jayaraman
sjayaraman at suse.de
Thu Apr 9 14:19:53 GMT 2009
Jeff Layton wrote:
> 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.
>
Oh, wait no storage is required I think. We reuse the pointer to wchar_t
and it seems char2uni() returns 1 or -EINVAL
and I was thinking strlen() on a wide char returns length in bytes?
fs/nls/nls_base.c
static int char2uni(const unsigned char *rawstring, int boundlen,
wchar_t *uni)
{
*uni = charset2uni[*rawstring];
if (*uni == 0x0000)
return -EINVAL;
return 1;
}
but, strnlen() may not work, though..
or am i looking at the wrong place..
>> +
>> + 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;
>> +}
>> +
>> +/*
>
>
--
Suresh Jayaraman
More information about the linux-cifs-client
mailing list