Re: Linux host controller string descriptors are odd-length

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

 



On 21 Aug 2009, George Spelvin wrote:

> I had some code that was using libusb to usb_get_string, which maps to
> 
>   struct usb_ctrltransfer ctrl;
>   char buf[256];
> 
>   ctrl.bRequestType = USB_ENDPOINT_IN;
>   ctrl.bRequest = request = USB_REQ_GET_DESCRIPTOR;
>   ctrl.wValue = (USB_DT_STRING << 8) + index;	// 3, 2 or 1
>   ctrl.wIndex = 0x0409;
>   ctrl.wLength = 256;
> 
>   ctrl.data = buf;
>   ctrl.timeout = 1000;
> 
>   return ioctl(dev->fd, IOCTL_USB_CONTROL, &ctrl);
> 
> Normally, this returns the length of the string descriptor, which
> is 2 + 2 * (number of unicode characters).  In fact, buf[0] equals the
> return value.
> 
> However, when addressing this request to something with idVendor = 0x1d6b,
> the return value is 1 more.  Some code I had a sanity check for that and
> choked.
> 
> It appears to be a deliberate decision inside ascii2utf() and rh_string(),
> but it ends up being different from real USB devices.
> 
> Isn't that kind of a bug?  I mean, the UTF-16 string is full of null
> bytes.  What benefit is there in adding another one?

Yes, this is a bug.  In ascii2utf, this line:

	if (utfmax > 0) {

should be replaced with this:

	if (*s && utfmax > 0) {

Alan Stern

--
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