From aa6ec9d92e9109510650d121db7cc7bee76638a0 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Mon, 17 Aug 2020 08:40:33 -0700 Subject: [PATCH] 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 --- libusb/os/windows_winusb.c | 4 ++++ libusb/version_nano.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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); 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 -- 2.7.4