From: Romain Tartière Date: Tue, 28 Nov 2017 19:07:29 +0000 (+0100) Subject: Check usb_get_port_path() return value X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6c1a76d1263403f908ac31271a4fd01792488545;p=libsigrok.git Check usb_get_port_path() return value This function can fail. If so, do not ignore the failure. --- diff --git a/src/device.c b/src/device.c index 6fcad410..519a1726 100644 --- a/src/device.c +++ b/src/device.c @@ -753,7 +753,9 @@ SR_API const char *sr_dev_inst_connid_get(const struct sr_dev_inst *sdi) if (b != usb->bus || a != usb->address) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + ((struct sr_dev_inst *)sdi)->connection_id = g_strdup(connection_id); break; } diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index fb35879f..694bd54a 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -194,7 +194,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_close(hdl); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; if (!strcmp(product, "ChronoVu LA8")) model = 0; diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index a7eb1948..08d9f0b6 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -216,7 +216,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_close(hdl); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; prof = NULL; for (j = 0; supported_device[j].vid; j++) { diff --git a/src/hardware/dreamsourcelab-dslogic/protocol.c b/src/hardware/dreamsourcelab-dslogic/protocol.c index 2096073c..0f171518 100644 --- a/src/hardware/dreamsourcelab-dslogic/protocol.c +++ b/src/hardware/dreamsourcelab-dslogic/protocol.c @@ -568,7 +568,9 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) if ((sdi->status == SR_ST_INITIALIZING) || (sdi->status == SR_ST_INACTIVE)) { /* Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index abb86788..647aeec0 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -265,7 +265,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_close(hdl); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; prof = NULL; for (j = 0; supported_fx2[j].vid; j++) { diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index fc6fd331..ec2b5c01 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -174,7 +174,9 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) /* * Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; diff --git a/src/hardware/hantek-4032l/api.c b/src/hardware/hantek-4032l/api.c index 626175f0..67dc968d 100644 --- a/src/hardware/hantek-4032l/api.c +++ b/src/hardware/hantek-4032l/api.c @@ -180,7 +180,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) des.idProduct != H4032L_USB_PRODUCT) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->driver = &hantek_4032l_driver_info; diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 01cba566..899dc867 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -217,7 +217,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_get_device_descriptor(devlist[i], &des); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; prof = NULL; for (j = 0; dev_profiles[j].orig_vid; j++) { diff --git a/src/hardware/hantek-6xxx/protocol.c b/src/hardware/hantek-6xxx/protocol.c index 8e406ffe..75d8ab91 100644 --- a/src/hardware/hantek-6xxx/protocol.c +++ b/src/hardware/hantek-6xxx/protocol.c @@ -46,7 +46,9 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) /* * Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 48beebfc..abbeb21b 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -315,7 +315,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_get_device_descriptor(devlist[i], &des); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; prof = NULL; for (j = 0; dev_profiles[j].orig_vid; j++) { diff --git a/src/hardware/hantek-dso/protocol.c b/src/hardware/hantek-dso/protocol.c index 39d87c44..c74187ad 100644 --- a/src/hardware/hantek-dso/protocol.c +++ b/src/hardware/hantek-dso/protocol.c @@ -130,7 +130,9 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi) /* * Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index 6dd0bd01..e75b5b09 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -134,7 +134,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (des.idVendor != LOGICSTUDIO16_VID) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; usb = NULL; @@ -210,7 +211,8 @@ static int open_device(struct sr_dev_inst *sdi) des.idProduct != LOGICSTUDIO16_PID_HAVE_FIRMWARE) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; /* * Check if this device is the same one that we associated diff --git a/src/hardware/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index a7e04548..ae444dd8 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -240,7 +240,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (des.idVendor != 0x21a9 || des.idProduct != 0x1006) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INITIALIZING; diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index dedb9a24..ed9e1ecd 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -188,7 +188,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_get_device_descriptor(devlist[i], &des); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID) continue; @@ -266,7 +267,9 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) /* * Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 90fb65ca..43a5f251 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -109,7 +109,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (strncmp(manufacturer, "testo", 5)) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; /* Hardcode the 435 for now. */ if (strcmp(product, "testo 435/635/735")) diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 6a9b774f..d415a3f9 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -69,7 +69,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (des.idVendor != VICTOR_VID || des.idProduct != VICTOR_PID) continue; - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index da3899dd..c2d1424b 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -196,7 +196,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_close(hdl); - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; prof = NULL; for (j = 0; j < zeroplus_models[j].vid; j++) {