Skip to content

Commit

Permalink
libusb: fix crash in hid_enumerate() caused by a stale device handle (#…
Browse files Browse the repository at this point in the history
…526)

When hid_enumerate() iterates over the device list, it's possible
that libusb_open() fails. If this occurs on the next round after
a successful libusb_open() call, create_device_info_for_device()
is passed the previous iteration's already closed device handle.

Fix the crash by setting the handle to NULL after libusb_close().
  • Loading branch information
imaami authored Apr 10, 2023
1 parent c1b9d2a commit 9f185ec
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,10 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
cur_dev = tmp;
}

if (res >= 0)
if (res >= 0) {
libusb_close(handle);
handle = NULL;
}
}
} /* altsettings */
} /* interfaces */
Expand Down

0 comments on commit 9f185ec

Please sign in to comment.