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>
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 @@ 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);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h index df646ec..46e8daf 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h
@@ -1 +1 @@ -#define LIBUSB_NANO 11535 +#define LIBUSB_NANO 11536