From patchwork Tue Jul 31 10:45:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 1258981 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id C2B723FC71 for ; Tue, 31 Jul 2012 10:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755656Ab2GaKpj (ORCPT ); Tue, 31 Jul 2012 06:45:39 -0400 Received: from smtp.eu.citrix.com ([62.200.22.115]:16227 "EHLO SMTP.EU.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755648Ab2GaKpi (ORCPT ); Tue, 31 Jul 2012 06:45:38 -0400 X-IronPort-AV: E=Sophos;i="4.77,682,1336348800"; d="scan'208";a="13777883" Received: from lonpmailmx02.citrite.net ([10.30.203.163]) by LONPIPO01.EU.CITRIX.COM with ESMTP/TLS/RC4-MD5; 31 Jul 2012 10:45:37 +0000 Received: from LONPMAILBOX01.citrite.net ([10.30.224.160]) by LONPMAILMX02.citrite.net ([10.30.203.163]) with mapi; Tue, 31 Jul 2012 11:45:36 +0100 From: Frediano Ziglio To: "sfrench@samba.org" CC: "linux-cifs@vger.kernel.org" Date: Tue, 31 Jul 2012 11:45:35 +0100 Subject: [PATCH] Convert properly UTF-8 to UTF-16 Thread-Topic: [PATCH] Convert properly UTF-8 to UTF-16 Thread-Index: Ac1vCZ2fyNn4rJPdTz2jZ7dQevyu8g== Message-ID: <7CE799CC0E4DE04B88D5FDF226E18AC2CDFFB08CFE@LONPMAILBOX01.citrite.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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 --- fs/cifs/cifs_unicode.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) if (charlen < 1) { @@ -215,6 +228,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; } diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 7dab9c0..a798e01 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -203,6 +203,19 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len, int i; wchar_t wchar_to; /* needed to quiet sparse */ + if (!strcmp(codepage->charset, "utf8")) { + i = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN, + (wchar_t *) to, len); + 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);