Skip to content

Commit

Permalink
Merge pull request #1815 from stefanrueger/usbhidopen-sn-sigfault
Browse files Browse the repository at this point in the history
Guard serial_number access in usbhid_open() to avoid segfault
  • Loading branch information
stefanrueger authored Jun 1, 2024
2 parents 0033d2d + e0a5d47 commit 48b5874
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/usb_hidapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor

walk = list;
while (walk) {
pmsg_notice("usbhid_open(): found %ls, serno: %ls\n", walk->product_string, walk->serial_number);
size_t slen = wcslen(walk->serial_number);
if (slen >= serlen && wcscmp(walk->serial_number + slen - serlen, wserno) == 0)
{
/* Found matching serial number */
break;
if(walk->serial_number) {
pmsg_notice("usbhid_open(): found %ls, serno: %ls\n", walk->product_string, walk->serial_number);
size_t slen = wcslen(walk->serial_number);
// Found matching serial number?
if (slen >= serlen && wcscmp(walk->serial_number + slen - serlen, wserno) == 0)
break;
pmsg_debug("usbhid_open(): serial number does not match\n");
}
pmsg_debug("usbhid_open(): serial number does not match\n");
walk = walk->next;
}
if (walk == NULL) {
Expand Down

0 comments on commit 48b5874

Please sign in to comment.