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 <yumkam@gmail.com>
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2017-05-31 09:49:54 +09:00
parent 663e5ed073
commit 5c33649782
1 changed files with 15 additions and 4 deletions

View File

@ -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);