Skip to content

Commit 9f185ec

Browse files
authored
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().
1 parent c1b9d2a commit 9f185ec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libusb/hid.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,10 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
833833
cur_dev = tmp;
834834
}
835835

836-
if (res >= 0)
836+
if (res >= 0) {
837837
libusb_close(handle);
838+
handle = NULL;
839+
}
838840
}
839841
} /* altsettings */
840842
} /* interfaces */

0 commit comments

Comments
 (0)