Skip to content

Commit

Permalink
usb: gadget: g_dnl: fix g_dnl_set_serialnumber()
Browse files Browse the repository at this point in the history
instead of only copying if strlen(s) is less than 32 characters, let's
just copy at most 31 characters regardless of the size of
serial#. This will guarantee that we always have a serial number if
serial# environment variable is set to anything.

Note that without a proper serial number, USB Command Verifier fails
our test of Device Descriptor since we will claim to have a serial
number without really providing one when requested.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  • Loading branch information
Felipe Balbi authored and Marek Vasut committed Feb 26, 2017
1 parent 00e9d69 commit 949bf79
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/usb/gadget/g_dnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;
void g_dnl_set_serialnumber(char *s)
{
memset(g_dnl_serial, 0, MAX_STRING_SERIAL);
if (strlen(s) < MAX_STRING_SERIAL)
strncpy(g_dnl_serial, s, strlen(s));
strncpy(g_dnl_serial, s, MAX_STRING_SERIAL - 1);
}

static struct usb_device_descriptor device_desc = {
Expand Down

0 comments on commit 949bf79

Please sign in to comment.