Ticket #43 (closed enhancement: fixed)
[PATCH] Don't allow desc_index=0 in libusb_get_string_descriptor_ascii
| Reported by: | Hannibal | Owned by: | Hannibal |
|---|---|---|---|
| Component: | libusb-1.0 | Keywords: | |
| Cc: | Blocked By: | ||
| Blocks: |
Description
As libusb_get_string_descriptor_ascii fetch by its own language list located on string index=0, fetching lang index by user request is probably programmer error. So make call with desc_index=0 return with INVALID_PARAM error.
This can also prevent some (probably buggy) device form erroneous behaviour. See my thread on libusb-devel ("Problem with new CUPS libusb backend").
Attachments
Change History
Changed 21 months ago by Hannibal
- Attachment libusb.diff added
comment:1 Changed 20 months ago by dsd
libusb generally doesn't attempt to detect erroneous behaviour of the programmer. Instead, the programmer should be fixed ;)
But I might consider taking this. What's the result of calling this function on descriptor 0 before your patch is applied?
comment:2 Changed 20 months ago by Hannibal
If you ask, what it returns - I don't know. But I can write a program to check this.
More important is that OKI 14ex printer stop to print after this call. It has has all string desciptors = 0, so this device haven't string descriptors at all.
USB 1.1 (my case) specs doesn't tell explictly what device should return in that case, so the device can return anything. It may looks like LANGID table which can cause next call to have wrong params for sure.
It can happen with other indexes also - but this is less likely. Indexes are mostly read form device descriptors, not set explictly. So LANGID table i that case exists for sure.
Of course this patch can be more sofisticated. libusb can check if all string descriptors are 0, and don't allow to fetch any descriptor in that case. This should also fix my problem ;). But this will need more ovehead on init (or worse on fetch) - nevertheless it can be useful in debug mode.
comment:4 Changed 16 months ago by hannibal
With latest git version, using program I'v attached to this ticket, I have:
my faulty printer:
./getdevserial 0x6BC 0xB
ASCII Length: -9; Text: �� ���
RAW Length: -9; Text: �� ���
proper working scanner:
./getdevserial 0x4A9 0x220E
ASCII Length: 1; Text: ?
RAW Length: 4; Text: o�
It seems it return LIBUSB_ERROR_PIPE.
comment:5 Changed 15 months ago by stuge
The email thread is at http://marc.info/?t=127378047900003
The fault is absolutely with any program which fails to validate that dev.iSerialNumber != 0 before calling libusb_get_string_descriptor_ascii().
But we might as well check for it in the library, it's easy enough. Will commit.
Patch against 1.0.8