From 5c33649782bf255af5a55f16eac5e85f059b00bf Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 31 May 2017 09:49:54 +0900 Subject: [PATCH] scd: Handle a failure of libusb_init. * scd/ccid-driver.c (ccid_get_reader_list, ccid_dev_scan): Handle failure. -- Reported-by: Yuriy M. Kaminskiy Signed-off-by: NIIBE Yutaka --- scd/ccid-driver.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c index fbbd1578d..1d5e8f26d 100644 --- a/scd/ccid-driver.c +++ b/scd/ccid-driver.c @@ -1228,7 +1228,12 @@ ccid_get_reader_list (void) if (!initialized_usb) { - libusb_init (NULL); + int rc; + if ((rc = libusb_init (NULL))) + { + DEBUGOUT_1 ("usb_init failed: %s.\n", libusb_error_name (rc)); + return NULL; + } initialized_usb = 1; } @@ -1292,9 +1297,17 @@ ccid_dev_scan (int *idx_max_p, struct ccid_dev_table **t_p) int idx = 0; int err = 0; + *idx_max_p = 0; + *t_p = NULL; + if (!initialized_usb) { - libusb_init (NULL); + int rc; + if ((rc = libusb_init (NULL))) + { + DEBUGOUT_1 ("usb_init failed: %s.\n", libusb_error_name (rc)); + return gpg_error (GPG_ERR_NOT_FOUND); + } initialized_usb = 1; } @@ -1373,8 +1386,6 @@ ccid_dev_scan (int *idx_max_p, struct ccid_dev_table **t_p) if (err) { - *idx_max_p = 0; - *t_p = NULL; for (i = 0; i < idx; i++) { free (ccid_dev_table[idx].ifcdesc_extra);