Author Message

<  Everything Coding  ~  Missing check for libusb_init() return code

PostPosted: Tue Mar 24, 2015 4:48 pm Reply with quote
Posts: 1 Joined: Tue Mar 24, 2015 4:45 pm
If libusb_init() fails, usb_modeswitch will segfault in the libusb_set_debug() call.

Code:
diff -urN usb-modeswitch-2.2.1/usb_modeswitch.c usb-modeswitch-2.2.1p0/usb_modeswitch.c
--- usb-modeswitch-2.2.1/usb_modeswitch.c       2015-01-14 21:13:59.000000000 +0100
+++ usb-modeswitch-2.2.1p0/usb_modeswitch.c     2015-03-24 15:41:57.000000000 +0100
@@ -425,6 +425,7 @@
        int numDefaults=0, sonySuccess=0;
        int currentConfig=0, defaultClass=0, interfaceClass=0;
        struct libusb_device_descriptor descriptor;
+       enum libusb_error libusbError;
 
        /* Make sure we have empty strings even if not set by config */
        TargetProductList[0] = '\0';
@@ -492,7 +493,10 @@
        }
 
        /* libusb initialization */
-       libusb_init(&ctx);
+       if ((libusbError = libusb_init(&ctx)) != LIBUSB_SUCCESS) {
+               fprintf(stderr, "Error: Failed to initialize libusb. %s(%d): %s\n\n", libusb_error_name(libusbError), libusbError, libusb_strerror(libusbError));
+               exit(1);
+       }
 
        if (verbose)
                libusb_set_debug(ctx, 3);


Offline
PostPosted: Tue Mar 24, 2015 8:02 pm Reply with quote
Site Admin Posts: 6443 Joined: Sat Nov 03, 2007 12:30 am
Thanks, good point, will apply the patch for the next release !!


Offline

Display posts from previous:  Sort by:

All times are UTC+02:00
Page 1 of 1
2 posts
Users browsing this forum: No registered users and 1 guest
Search for:
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum