Re: [PATCH] Gadget: fix UTF conversion in the usbstring library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 27 April 2009, Alan Stern wrote:
> 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@xxxxxxxxxxxxxxxxxxx>

Gaak!  Yes.  In fact, *only* such continuation bytes
may have those bits set to 10; 0* and 11 are reserved
for initial bytes.  That allows internal resynch in
case someone drops a byte now and then.

Acked-by: David Brownell <dbrownell@xxxxxxxxxxxxxxxxxxxxx>


> CC: David Brownell <david-b@xxxxxxxxxxx>
> 
> ---
> 
> Index: usb-2.6/drivers/usb/gadget/usbstring.c
> ===================================================================
> --- usb-2.6.orig/drivers/usb/gadget/usbstring.c
> +++ usb-2.6/drivers/usb/gadget/usbstring.c
> @@ -38,7 +38,7 @@ static int utf8_to_utf16le(const char *s
>  				uchar = (c & 0x1f) << 6;
>  
>  				c = (u8) *s++;
> -				if ((c & 0xc0) != 0xc0)
> +				if ((c & 0xc0) != 0x80)
>  					goto fail;
>  				c &= 0x3f;
>  				uchar |= c;
> @@ -49,13 +49,13 @@ static int utf8_to_utf16le(const char *s
>  				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;
> 
> 



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux