Skip to content

Commit

Permalink
USB: Gadget: fix UTF conversion in the usbstring library
Browse files Browse the repository at this point in the history
This patch (as1234) fixes a bug in the UTF8 -> UTF-16 conversion
routine in the gadget/usbstring library.  In a UTF-8 multi-byte
sequence, all bytes after the first should have their high-order
two bits set to 10, not 11.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Alan Stern authored and Greg Kroah-Hartman committed May 9, 2009
1 parent 72a772a commit 0f43158
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/usb/gadget/usbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len)
uchar = (c & 0x1f) << 6;

c = (u8) *s++;
if ((c & 0xc0) != 0xc0)
if ((c & 0xc0) != 0x80)
goto fail;
c &= 0x3f;
uchar |= c;
Expand All @@ -49,13 +49,13 @@ static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len)
uchar = (c & 0x0f) << 12;

c = (u8) *s++;
if ((c & 0xc0) != 0xc0)
if ((c & 0xc0) != 0x80)
goto fail;
c &= 0x3f;
uchar |= c << 6;

c = (u8) *s++;
if ((c & 0xc0) != 0xc0)
if ((c & 0xc0) != 0x80)
goto fail;
c &= 0x3f;
uchar |= c;
Expand Down

0 comments on commit 0f43158

Please sign in to comment.