From: Vincent Palatin Date: Mon, 10 Nov 2014 16:17:07 +0000 (-0800) Subject: usb_get_port_path(): fix libusb error checking X-Git-Tag: libsigrok-0.4.0~716 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2f004b4bc15c891b474adcba59a2224f009828af;p=libsigrok.git usb_get_port_path(): fix libusb error checking When libusb cannot access a device, libusb_get_port_numbers() will return an error. Check the return code rather than doing invalid pointer operations (out-of-bound read). Avoid segfaults at sigrok-cli startup on my setup where some USB devices are not accessible and also make Valgrind happier. Signed-off-by: Vincent Palatin --- diff --git a/src/usb.c b/src/usb.c index ec502c97..8bdb8d60 100644 --- a/src/usb.c +++ b/src/usb.c @@ -278,6 +278,9 @@ SR_PRIV int usb_get_port_path(libusb_device *dev, char *path, int path_len) n = libusb_get_port_numbers(dev, port_numbers, sizeof(port_numbers)); + if (n < 1) + return SR_ERR; + len = snprintf(path, path_len, "usb/%d-%d", libusb_get_bus_number(dev), port_numbers[0]);