tinyusb: Correct descriptor string length calculation#182
tinyusb: Correct descriptor string length calculation#182hathach merged 1 commit intoadafruit:masterfrom kaysievers:tinyusb-descriptor-len
Conversation
|
This is a real bug which should be fixed. Could you please have a look? Thanks! |
|
@hathach can take a look |
| int buflen = 0; | ||
|
|
||
| while (i < bufsize) { | ||
| while (s[i] > 0 && i < bufsize) { |
There was a problem hiding this comment.
thanks for the PR, though should the extra condition is s[i] != 0 if we are trying to find the null terminator ?
There was a problem hiding this comment.
Oh, I am used to char being unsigned. You are right, checking !=0 should be safer and work in any case.
There was a problem hiding this comment.
@kaysievers yeah, would you mind pushing the update so that we could merge and fix this :).
There was a problem hiding this comment.
Rebased and pushed with the fix. Tested it and dumped the descriptor, looks like the string lengths are fine:
String Descriptor Table
--------------------------------
Index LANGID String
0x00 0x0000 0x0409
Hex dump:
0x04 0x03 0x09 0x04
0x01 0x0409 "V2"
Hex dump:
0x06 0x03 0x56 0x00 0x32 0x00
0x02 0x0409 "pad"
Hex dump:
0x08 0x03 0x70 0x00 0x61 0x00 0x64 0x00
0x03 0x0409 "226B0C055333395336202020FF093B13"
Hex dump:
0x42 0x03 0x32 0x00 0x32 0x00 0x36 0x00 0x42 0x00
0x30 0x00 0x43 0x00 0x30 0x00 0x35 0x00 0x35 0x00
0x33 0x00 0x33 0x00 0x33 0x00 0x33 0x00 0x39 0x00
0x35 0x00 0x33 0x00 0x33 0x00 0x36 0x00 0x32 0x00
0x30 0x00 0x32 0x00 0x30 0x00 0x32 0x00 0x30 0x00
0x46 0x00 0x46 0x00 0x30 0x00 0x39 0x00 0x33 0x00
0x42 0x00 0x31 0x00 0x33 0x00
This fixes strcpy_uni16() to return the correct number of characters. It wasn't visible in the host so far, because the strings have been NUL terminated.
hathach
left a comment
There was a problem hiding this comment.
thank you very much for the PR. Btw, I am still in the middle of other works, and haven't got time to work on your multiple MIDI pr although I really like to support multiple MIDIs. Please give me a bit more time :)
This fixes strcpy_uni16() to return the correct number of characters.
It wasn't visible in the host so far, because the strings have been NUL
terminated.