Windows: Prevent NULL pointer dereference when ancestor is missing
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 17 Aug 2020 15:40:33 +0000 (08:40 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Mon, 17 Aug 2020 15:40:33 +0000 (08:40 -0700)
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>
libusb/os/windows_winusb.c
libusb/version_nano.h

index fa6721e..75088c6 100644 (file)
@@ -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);
index df646ec..46e8daf 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11535
+#define LIBUSB_NANO 11536