From: Jeff Layton <jlayton@redhat.com>
To: Frediano Ziglio <frediano.ziglio@citrix.com>
Cc: "sfrench@samba.org" <sfrench@samba.org>,
"linux-cifs@vger.kernel.org" <linux-cifs@vger.kernel.org>,
"samba-technical@lists.samba.org"
<samba-technical@lists.samba.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] Convert properly UTF-8 to UTF-16
Date: Tue, 7 Aug 2012 06:47:52 -0400 [thread overview]
Message-ID: <20120807064752.22e0da81@corrin.poochiereds.net> (raw)
In-Reply-To: <7CE799CC0E4DE04B88D5FDF226E18AC2CDFFB08D16@LONPMAILBOX01.citrite.net>
On Tue, 7 Aug 2012 10:33:03 +0100
Frediano Ziglio <frediano.ziglio@citrix.com> wrote:
>
> wchar_t is currently 16bit so converting a utf8 encoded characters not
> in plane 0 (>= 0x10000) to wchar_t (that is calling char2uni) lead to a
> -EINVAL return. This patch detect utf8 in cifs_strtoUTF16 and add special
> code calling utf8s_to_utf16s.
>
> Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
> ---
> fs/cifs/cifs_unicode.c | 22 ++++++++++++++++++++++
> 1 files changed, 22 insertions(+), 0 deletions(-)
>
> diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
> index 7dab9c0..1166b95 100644
> --- a/fs/cifs/cifs_unicode.c
> +++ b/fs/cifs/cifs_unicode.c
> @@ -203,6 +203,27 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len,
> int i;
> wchar_t wchar_to; /* needed to quiet sparse */
>
> + /* special case for utf8 to handle no plane0 chars */
> + if (!strcmp(codepage->charset, "utf8")) {
> + /*
> + * convert utf8 -> utf16, we assume we have enough space
> + * as caller should have assumed conversion does not overflow
> + * in destination len is length in wchar_t units (16bits)
> + */
> + i = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN,
> + (wchar_t *) to, len);
> +
> + /* if success terminate and exit */
> + if (i >= 0)
> + goto success;
> + /*
> + * if fails fall back to UCS encoding as this
> + * function should not return negative values
> + * currently can fail only if source contains
> + * invalid encoded characters
> + */
> + }
> +
> for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
> charlen = codepage->char2uni(from, len, &wchar_to);
> if (charlen < 1) {
> @@ -215,6 +236,7 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len,
> put_unaligned_le16(wchar_to, &to[i]);
> }
>
> +success:
> put_unaligned_le16(0, &to[i]);
> return i;
> }
Looks reasonable...
Acked-by: Jeff Layton <jlayton@redhat.com>
next prev parent reply other threads:[~2012-08-07 10:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-07 9:33 Frediano Ziglio
2012-08-07 10:47 ` Jeff Layton [this message]
2012-08-28 7:28 ` Frediano Ziglio
2012-10-03 14:34 ` Frediano Ziglio
2012-10-03 19:49 ` Steve French
2012-10-08 8:18 ` Frediano Ziglio
2012-10-08 11:26 ` Jeff Layton
2012-10-08 14:04 ` Steve French
2012-10-09 4:43 ` Suresh Jayaraman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120807064752.22e0da81@corrin.poochiereds.net \
--to=jlayton@redhat.com \
--cc=frediano.ziglio@citrix.com \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=samba-technical@lists.samba.org \
--cc=sfrench@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®