summaryrefslogtreecommitdiff
path: root/libusb/os/windows_winusb.c
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-08-17 08:40:33 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2020-08-17 08:40:33 -0700
commitaa6ec9d92e9109510650d121db7cc7bee76638a0 (patch)
treedc6b07499bb1b3ef814f8999cd2cbca99273b92e /libusb/os/windows_winusb.c
parentfa3f91e7c4c73fd233104cf3cad4890dd6121043 (diff)
downloadlibusb-aa6ec9d92e9109510650d121db7cc7bee76638a0.tar.gz
Windows: Prevent NULL pointer dereference when ancestor is missing
A buggy virtual USB device driver can cause the device enumeration process to fail during the init_device() function when trying to determine the bus number of the device. Guard against this by checking that the ancestor device was actually found and skipping the bogus device when there is no ancestor. Closes #491 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/os/windows_winusb.c')
-rw-r--r--libusb/os/windows_winusb.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index fa6721e..75088c6 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -823,6 +823,10 @@ static int init_device(struct libusb_device *dev, struct libusb_device *parent_d
for (depth = 1; bus_number == 0; depth++) {
tmp_dev = get_ancestor(ctx, devinst, &devinst);
+ if (tmp_dev == NULL) {
+ usbi_warn(ctx, "ancestor for device '%s' not found at depth %u", priv->dev_id, depth);
+ return LIBUSB_ERROR_NO_DEVICE;
+ }
if (tmp_dev->bus_number != 0) {
bus_number = tmp_dev->bus_number;
tmp_priv = usbi_get_device_priv(tmp_dev);