From 2a241c9efcf4c422c64307e1034e156965e770d2 Mon Sep 17 00:00:00 2001 From: msweet Date: Mon, 13 May 2013 16:46:08 +0000 Subject: [PATCH] cups.org: libusb-based backend can crash if USB is disabled in BIOS git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10977 a1ca3aef-8c08-0410-bb20-df032aa958be --- CHANGES-1.6.txt | 2 ++ backend/usb-libusb.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGES-1.6.txt b/CHANGES-1.6.txt index 26151353d4..22d8710686 100644 --- a/CHANGES-1.6.txt +++ b/CHANGES-1.6.txt @@ -5,6 +5,8 @@ CHANGES IN CUPS V1.6.3 - The configure script now prefers Clang over GCC. - Fixed a compile problem on AIX (STR #4307) + - The USB backend could crash on libusb-based systems if USB was + disabled in the BIOS () - Fixed a rounding error in the PWG media size mapping code () - Fixed several ipptool test files that used old STATUS names. diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c index bbce39a62e..dc32bd082b 100644 --- a/backend/usb-libusb.c +++ b/backend/usb-libusb.c @@ -899,7 +899,8 @@ find_device(usb_cb_t cb, /* I - Callback function */ /* Pointer to current alternate setting */ const struct libusb_endpoint_descriptor *endpptr = NULL; /* Pointer to current endpoint */ - ssize_t numdevs, /* number of connected devices */ + ssize_t err = 0, /* Error code */ + numdevs, /* number of connected devices */ i = 0; uint8_t conf, /* Current configuration */ iface, /* Current interface */ @@ -918,7 +919,14 @@ find_device(usb_cb_t cb, /* I - Callback function */ * Initialize libusb... */ - libusb_init(NULL); + err = libusb_init(NULL); + if (err) + { + fprintf(stderr, "DEBUG: Unable to initialize USB access via libusb, " + "libusb error %i\n", err); + return (NULL); + } + numdevs = libusb_get_device_list(NULL, &list); fprintf(stderr, "DEBUG: libusb_get_device_list=%d\n", (int)numdevs); @@ -1088,7 +1096,8 @@ find_device(usb_cb_t cb, /* I - Callback function */ * Clean up .... */ - libusb_free_device_list(list, 1); + if (numdevs >= 0) + libusb_free_device_list(list, 1); libusb_exit(NULL); return (NULL); -- 2.47.2