This is an automated email from Gerrit.

Andrey Smirnov ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/2059

-- gerrit

commit f0c6ebeff7ef66ddfae10e454f01670d4b75c6b1
Author: Andrey Smirnov <[email protected]>
Date:   Fri Mar 21 06:06:14 2014 -0700

    libusb1: Do not ignore errors returned by libusb_get_config_descriptor()
    
    Ignoring errors returned by libusb_get_config_descriptor in cases when
    user calls jtag_libusb_set_configuration with the configuration number
    that device does not support will result in segfault. Avoid that by
    adding explicit error checks and assert statements to make sure that
    'config' variable is not NULL when we start using it.
    
    Change-Id: I9be9f0d6984e53b16298adbe12761e3c8a974b89
    Signed-off-by: Andrey Smirnov <[email protected]>

diff --git a/src/jtag/drivers/libusb1_common.c 
b/src/jtag/drivers/libusb1_common.c
index c4478cb..d5efbf7 100644
--- a/src/jtag/drivers/libusb1_common.c
+++ b/src/jtag/drivers/libusb1_common.c
@@ -119,28 +119,56 @@ int 
jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
                int configuration)
 {
        struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
-       int retCode = -99;
+       int ret = -99;
 
        struct libusb_config_descriptor *config = NULL;
 
-       libusb_get_config_descriptor(udev, configuration, &config);
-       retCode = libusb_set_configuration(devh, config->bConfigurationValue);
+       ret = libusb_get_config_descriptor(udev, configuration, &config);
+       if (ret != 0) {
+               /* FIXME: It this codepathe is taken through a call
+                  from struct jtag_intergace -> init then this would
+                  fail with symbol lookup error being unable to find
+                  libusb_error_name. Need to fugure out why.
+               */
+
+               LOG_ERROR("libusb_get_config_descriptor() failed: %s",
+                         libusb_error_name(ret));
+               return ret;
+       }
 
-       libusb_free_config_descriptor(config);
+       assert(config != NULL);
 
-       return retCode;
+       ret = libusb_set_configuration(devh, config->bConfigurationValue);
+
+       libusb_free_config_descriptor(config);
+       return ret;
 }
 
 int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep)
 {
+       int ret;
        const struct libusb_interface *inter;
        const struct libusb_interface_descriptor *interdesc;
        const struct libusb_endpoint_descriptor *epdesc;
        struct libusb_config_descriptor *config;
 
-       libusb_get_config_descriptor(udev, 0, &config);
+       ret = libusb_get_config_descriptor(udev, 0, &config);
+       if (ret != 0) {
+               /* FIXME: It this codepathe is taken through a call
+                  from struct jtag_intergace -> init then this would
+                  fail with symbol lookup error being unable to find
+                  libusb_error_name. Need to fugure out why.
+               */
+
+               LOG_ERROR("libusb_get_config_descriptor() failed with %s",
+                         libusb_error_name(ret));
+               return ret;
+       }
+
+       assert(config != NULL);
+
        for (int i = 0; i < (int)config->bNumInterfaces; i++) {
                inter = &config->interface[i];
 

-- 

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to