Fix off-by-one in usb_decode_str_desc(). Previously it would decode

one character too many.  Note that this function is only used to decode
string descriptors generated by the kernel itself.

Reviewed by:	hselasky@
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Edward Tomasz Napierala 2018-05-17 15:19:29 +00:00
parent 6f78fad3b1
commit 2d1a76975e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333718

View File

@ -127,7 +127,12 @@ usb_decode_str_desc(struct usb_string_descriptor *sd, char *buf, size_t buflen)
{
size_t i;
for (i = 0; i < buflen - 1 && i < sd->bLength / 2; i++)
if (sd->bLength < 2) {
buf[0] = '\0';
return;
}
for (i = 0; i < buflen - 1 && i < (sd->bLength / 2) - 1; i++)
buf[i] = UGETW(sd->bString[i]);
buf[i] = '\0';