From: Guy Harris Date: Mon, 6 Aug 2012 22:25:30 +0000 (-0700) Subject: Check whether libusb_init() succeeds, and give up if it doesn't. X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/9364528b46624fd14a86662d54ea550a4f45fe14 Check whether libusb_init() succeeds, and give up if it doesn't. libusb_init() isn't guaranteed to succeed; it returns a (presumably) non-zero error on failure. If it doesn't return 0, just give up - we presumably don't have a valid libusb_context pointer, which is probably what's causing crashes when we call libusb_get_device_list() on a system with no usbfs mounted. This fixes bug 3554749 in the tracker, and a bunch of upstream bugs. --- diff --git a/pcap-canusb-linux.c b/pcap-canusb-linux.c index 5abfe18e..373f0a98 100644 --- a/pcap-canusb-linux.c +++ b/pcap-canusb-linux.c @@ -96,8 +96,15 @@ int canusb_platform_finddevs(pcap_if_t **alldevsp, char *err_str) unsigned char buf[96]; int cnt, i; - libusb_init(&fdctx); - + if (libusb_init(&fdctx) != 0) { + /* + * XXX - if this doesn't just mean "no USB file system mounted", + * perhaps we should report a real error rather than just + * saying "no CANUSB devices". + */ + return 0; + } + cnt = libusb_get_device_list(fdctx,&devs); for(i=0;i