From 9f185ec51025695ab004085600ddaafb252e1e42 Mon Sep 17 00:00:00 2001 From: Juuso Alasuutari Date: Mon, 10 Apr 2023 23:24:12 +0300 Subject: [PATCH] libusb: fix crash in hid_enumerate() caused by a stale device handle (#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(). --- libusb/hid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libusb/hid.c b/libusb/hid.c index caa558333..43e1756d9 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -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 */