Compare commits

...

No commits in common. "c9-beta" and "c8" have entirely different histories.
c9-beta ... c8

15 changed files with 1105 additions and 896 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
SOURCES/libusb-1.0.26.tar.bz2 SOURCES/libusb-1.0.23.tar.gz

View File

@ -1 +1 @@
0e25981dafb69729e5d976017d113410078f6f6d SOURCES/libusb-1.0.26.tar.bz2 c8ebcc7d0a14f910151b3066326d8ba126894b88 SOURCES/libusb-1.0.23.tar.gz

View File

@ -0,0 +1,38 @@
From 41b71fbf664efd6ba8a5233dfd1a1fca15228908 Mon Sep 17 00:00:00 2001
From: mrstock <info@niub.it>
Date: Fri, 20 Sep 2019 14:36:07 +0200
Subject: [PATCH 01/10] fix constant not in range of enumerated type
fix "Integer constant not in range of enumerated type 'enum libusb_transfer_status'"
LIBUSB_ERROR_NO_DEVICE doesn't exist on enum libusb_transfer_status
(cherry picked from commit 906e706f8abdff626370e59b880f340cf54e3632)
---
libusb/sync.c | 2 +-
libusb/version_nano.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libusb/sync.c b/libusb/sync.c
index 70942ac..863fe5c 100644
--- a/libusb/sync.c
+++ b/libusb/sync.c
@@ -62,7 +62,7 @@ static void sync_transfer_wait_for_completion(struct libusb_transfer *transfer)
}
if (NULL == transfer->dev_handle) {
/* transfer completion after libusb_close() */
- transfer->status = LIBUSB_ERROR_NO_DEVICE;
+ transfer->status = LIBUSB_TRANSFER_NO_DEVICE;
*completed = 1;
}
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 02179a4..dfa2fc9 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11397
+#define LIBUSB_NANO 11399
--
2.26.1

View File

@ -0,0 +1,33 @@
From 476239823fa3b800fda1ded87b60f9f7dd10cff2 Mon Sep 17 00:00:00 2001
From: Ludovic Rousseau <ludovic.rousseau@free.fr>
Date: Wed, 30 Oct 2019 12:56:47 +0100
Subject: [PATCH 02/10] Doxygen: add libusb_wrap_sys_device() in the API list
(cherry picked from commit e4923e77e953d10fa1edda70e2e57adc79cf1d12)
---
libusb/core.c | 1 +
libusb/version_nano.h | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/libusb/core.c b/libusb/core.c
index 741bf99..6d025fa 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -442,6 +442,7 @@ if (cfg != desired)
* - libusb_unlock_event_waiters()
* - libusb_unref_device()
* - libusb_wait_for_event()
+ * - libusb_wrap_sys_device()
*
* \section Structures
* - libusb_bos_descriptor
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index dfa2fc9..a41e19e 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11399
+#define LIBUSB_NANO 11404
--
2.26.1

View File

@ -0,0 +1,41 @@
From 686536a2862f0d69e0075316ef54c1f927d134a3 Mon Sep 17 00:00:00 2001
From: Ludovic Rousseau <ludovic.rousseau@free.fr>
Date: Fri, 1 Nov 2019 16:04:02 +0100
Subject: [PATCH 03/10] Linux backend: fix ressource leak
Issue detected by Coverity:
22. leaked_handle: Handle variable fd going out of scope leaks the handle.
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
(cherry picked from commit 1bb774ca7e5cb100e1fb7ac287e561b2155da70e)
---
libusb/os/linux_usbfs.c | 4 ++++
libusb/version_nano.h | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 63fe592..dace935 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -1049,7 +1049,11 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
}
if (sysfs_dir && sysfs_can_relate_devices)
+ {
+ if (fd != wrapped_fd)
+ close(fd);
return LIBUSB_SUCCESS;
+ }
/* cache active config */
if (wrapped_fd < 0)
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index a41e19e..aebe182 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11404
+#define LIBUSB_NANO 11411
--
2.26.1

View File

@ -0,0 +1,36 @@
From d3018d249a98fcf93d36baec32b80b7ef5a8ee68 Mon Sep 17 00:00:00 2001
From: Slash Gordon <slash.gordon.dev@gmail.com>
Date: Tue, 3 Dec 2019 12:47:38 +0100
Subject: [PATCH 04/10] Linux: Improved system out of memory handling
Maps ENOMEM system error to LIBUSB_ERROR_NO_MEM.
(cherry picked from commit 97ece77c4a6eaafd0a74fd3b73e290ec97d71eb5)
---
libusb/os/linux_usbfs.c | 2 ++
libusb/version_nano.h | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index dace935..53530cd 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -2079,6 +2079,8 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer)
if (r < 0) {
if (errno == ENODEV) {
r = LIBUSB_ERROR_NO_DEVICE;
+ } else if (errno == ENOMEM) {
+ r = LIBUSB_ERROR_NO_MEM;
} else {
usbi_err(TRANSFER_CTX(transfer),
"submiturb failed error %d errno=%d", r, errno);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index aebe182..41a03d1 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11411
+#define LIBUSB_NANO 11412
--
2.26.1

View File

@ -0,0 +1,46 @@
From 2922440e42230d3d1b63397e99efa331f499c755 Mon Sep 17 00:00:00 2001
From: John Keeping <john@metanate.com>
Date: Tue, 12 Nov 2019 14:01:40 +0000
Subject: [PATCH 05/10] linux_udev: silently ignore "bind" action
When a driver is bound to a device, udev emits a "bind" action that
causes libusb to log an error message:
libusb: error [udev_hotplug_event] ignoring udev action bind
Since we know this action is not relevant for libusb, silently ignore it
to avoid people thinking there is something wrong.
There is already a debug log entry for the action, so there is no need
to add a duplicate here.
Signed-off-by: John Keeping <john@metanate.com>
(cherry picked from commit f20f2be7825e34b5273af17fc0740c60bd352b32)
---
libusb/os/linux_udev.c | 2 ++
libusb/version_nano.h | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c
index bea03e3..b09d299 100644
--- a/libusb/os/linux_udev.c
+++ b/libusb/os/linux_udev.c
@@ -262,6 +262,8 @@ static void udev_hotplug_event(struct udev_device* udev_dev)
linux_hotplug_enumerate(busnum, devaddr, sys_name);
} else if (detached) {
linux_device_disconnected(busnum, devaddr);
+ } else if (strncmp(udev_action, "bind", 4) == 0) {
+ /* silently ignore "known unhandled" action */
} else {
usbi_err(NULL, "ignoring udev action %s", udev_action);
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 41a03d1..1764dec 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11412
+#define LIBUSB_NANO 11413
--
2.26.1

View File

@ -0,0 +1,294 @@
From 23557c82fd09b4ab7b106c13287a3ec8291f42dc Mon Sep 17 00:00:00 2001
From: Pino Toscano <toscano.pino@tiscali.it>
Date: Fri, 27 Dec 2019 18:41:28 +0100
Subject: [PATCH 06/10] Add Null POSIX backend
Add a simple null backend for POSIX platforms that reports no available
devices, and provides no capabilities. Make use of this new backend on
all the OSes without an existing backend, so libusb can be built even on
OSes without USB support.
(cherry picked from commit 53572d7e5eee79266139399924c7491174be1670)
---
configure.ac | 13 +++-
libusb/Makefile.am | 7 +-
libusb/libusbi.h | 2 +-
libusb/os/null_usb.c | 176 ++++++++++++++++++++++++++++++++++++++++++
libusb/version_nano.h | 2 +-
5 files changed, 196 insertions(+), 4 deletions(-)
create mode 100644 libusb/os/null_usb.c
diff --git a/configure.ac b/configure.ac
index da8a158..ddde325 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,7 +100,9 @@ case $host in
threads=posix
;;
*)
- AC_MSG_ERROR([unsupported operating system $host])
+ AC_MSG_RESULT([Null])
+ backend="null"
+ threads="posix"
esac
case $backend in
@@ -186,6 +188,14 @@ haiku)
AC_CHECK_HEADERS([poll.h])
AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
;;
+null)
+ AC_DEFINE(OS_NULL, 1, [Null backend])
+ AC_SUBST(OS_NULL)
+ THREAD_CFLAGS="-pthread"
+ LIBS="-pthread"
+ AC_CHECK_HEADERS([poll.h])
+ AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
+ ;;
esac
AC_SUBST(LIBS)
@@ -197,6 +207,7 @@ AM_CONDITIONAL(OS_SUNOS, test "x$backend" = xsunos)
AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
+AM_CONDITIONAL(OS_NULL, test "x$backend" = xnull)
AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = xyes)
AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
index e4da62e..466b633 100644
--- a/libusb/Makefile.am
+++ b/libusb/Makefile.am
@@ -22,13 +22,14 @@ WINDOWS_USB_SRC = libusb-1.0.def libusb-1.0.rc \
WINCE_USB_SRC = os/wince_usb.h os/wince_usb.c
HAIKU_USB_SRC = os/haiku_usb.h os/haiku_usb_backend.cpp \
os/haiku_usb_raw.h os/haiku_usb_raw.cpp os/haiku_pollfs.cpp
+NULL_USB_SRC = os/null_usb.c
EXTRA_DIST = $(POSIX_POLL_SRC) $(POSIX_THREADS_SRC) \
$(WINDOWS_POLL_SRC) $(WINDOWS_THREADS_SRC) \
$(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) \
$(OPENBSD_USB_SRC) $(NETBSD_USB_SRC) \
$(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \
- $(HAIKU_USB_SRC) \
+ $(HAIKU_USB_SRC) $(NULL_USB_SRC) \
os/linux_udev.c os/linux_netlink.c
if OS_LINUX
@@ -64,6 +65,10 @@ libusb_haiku_la_SOURCES = $(HAIKU_USB_SRC)
libusb_1_0_la_LIBADD = libusb_haiku.la
endif
+if OS_NULL
+OS_SRC = $(NULL_USB_SRC)
+endif
+
if OS_WINDOWS
OS_SRC = $(WINDOWS_USB_SRC)
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 0a677bd..4cb6141 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -575,7 +575,7 @@ int usbi_clear_event(struct libusb_context *ctx);
/* Internal abstraction for poll (needs struct usbi_transfer on Windows) */
#if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
- defined(OS_HAIKU) || defined(OS_SUNOS)
+ defined(OS_HAIKU) || defined(OS_SUNOS) || defined(OS_NULL)
#include <unistd.h>
#include "os/poll_posix.h"
#elif defined(OS_WINDOWS) || defined(OS_WINCE)
diff --git a/libusb/os/null_usb.c b/libusb/os/null_usb.c
new file mode 100644
index 0000000..97fa0b8
--- /dev/null
+++ b/libusb/os/null_usb.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright © 2019 Pino Toscano <toscano.pino@tiscali.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libusbi.h"
+
+static int
+null_get_device_list(struct libusb_context * ctx,
+ struct discovered_devs **discdevs)
+{
+ return LIBUSB_SUCCESS;
+}
+
+static int
+null_open(struct libusb_device_handle *handle)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static void
+null_close(struct libusb_device_handle *handle)
+{
+}
+
+static int
+null_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
+ int *host_endian)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_get_active_config_descriptor(struct libusb_device *dev,
+ unsigned char *buf, size_t len, int *host_endian)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
+ unsigned char *buf, size_t len, int *host_endian)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_set_configuration(struct libusb_device_handle *handle, int config)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_claim_interface(struct libusb_device_handle *handle, int iface)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_release_interface(struct libusb_device_handle *handle, int iface)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
+ int altsetting)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_reset_device(struct libusb_device_handle *handle)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_submit_transfer(struct usbi_transfer *itransfer)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_cancel_transfer(struct usbi_transfer *itransfer)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static void
+null_clear_transfer_priv(struct usbi_transfer *itransfer)
+{
+}
+
+static int
+null_handle_transfer_completion(struct usbi_transfer *itransfer)
+{
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+}
+
+static int
+null_clock_gettime(int clkid, struct timespec *tp)
+{
+ switch (clkid) {
+ case USBI_CLOCK_MONOTONIC:
+ return clock_gettime(CLOCK_REALTIME, tp);
+ case USBI_CLOCK_REALTIME:
+ return clock_gettime(CLOCK_REALTIME, tp);
+ default:
+ return LIBUSB_ERROR_INVALID_PARAM;
+ }
+}
+
+const struct usbi_os_backend usbi_backend = {
+ .name = "Null backend",
+ .caps = 0,
+ .init = NULL,
+ .exit = NULL,
+ .set_option = NULL,
+ .get_device_list = null_get_device_list,
+ .hotplug_poll = NULL,
+ .wrap_sys_device = NULL,
+ .open = null_open,
+ .close = null_close,
+ .get_device_descriptor = null_get_device_descriptor,
+ .get_active_config_descriptor = null_get_active_config_descriptor,
+ .get_config_descriptor = null_get_config_descriptor,
+ .get_config_descriptor_by_value = NULL,
+ .get_configuration = NULL,
+ .set_configuration = null_set_configuration,
+ .claim_interface = null_claim_interface,
+ .release_interface = null_release_interface,
+ .set_interface_altsetting = null_set_interface_altsetting,
+ .clear_halt = null_clear_halt,
+ .reset_device = null_reset_device,
+ .alloc_streams = NULL,
+ .free_streams = NULL,
+ .dev_mem_alloc = NULL,
+ .dev_mem_free = NULL,
+ .kernel_driver_active = NULL,
+ .detach_kernel_driver = NULL,
+ .attach_kernel_driver = NULL,
+ .destroy_device = NULL,
+ .submit_transfer = null_submit_transfer,
+ .cancel_transfer = null_cancel_transfer,
+ .clear_transfer_priv = null_clear_transfer_priv,
+ .handle_events = NULL,
+ .handle_transfer_completion = null_handle_transfer_completion,
+ .clock_gettime = null_clock_gettime,
+#ifdef USBI_TIMERFD_AVAILABLE
+ .get_timerfd_clockid = NULL,
+#endif
+ .context_priv_size = 0,
+ .device_priv_size = 0,
+ .device_handle_priv_size = 0,
+ .transfer_priv_size = 0,
+};
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 1764dec..4150474 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11413
+#define LIBUSB_NANO 11415
--
2.26.1

View File

@ -0,0 +1,128 @@
From fec6ad30dcb5917f03a53676f4f3ac68126e2fde Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Fri, 10 Jan 2020 20:04:52 +0100
Subject: [PATCH 07/10] core: fix build warning on newer versions of gcc
When building libusb on a "newer" version of gcc (9.2), a lot of
warnings are thrown about zero-length messages as being part of a format
string.
An example of this is:
descriptor.c:546:11: warning: zero-length gnu_printf format string [-Wformat-zero-length]
546 | usbi_dbg("");
| ^~
Fix this up by replacing all calls of:
usbi_dbg("");
with
usbi_dbg(" ");
as obviously we still want to keep the implicit tracing message in the
log.
Closes #674
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
(cherry picked from commit 0bf84e4d516c4488e5fcf4b10e3a7263c13019e1)
---
libusb/core.c | 10 +++++-----
libusb/descriptor.c | 2 +-
libusb/io.c | 4 ++--
libusb/version_nano.h | 2 +-
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/libusb/core.c b/libusb/core.c
index 6d025fa..0048dad 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -813,7 +813,7 @@ ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
int r = 0;
ssize_t i, len;
USBI_GET_CONTEXT(ctx);
- usbi_dbg("");
+ usbi_dbg(" ");
if (!discdevs)
return LIBUSB_ERROR_NO_MEM;
@@ -1493,7 +1493,7 @@ void API_EXPORTED libusb_close(libusb_device_handle *dev_handle)
if (!dev_handle)
return;
- usbi_dbg("");
+ usbi_dbg(" ");
ctx = HANDLE_CTX(dev_handle);
handling_events = usbi_handling_events(ctx);
@@ -1576,7 +1576,7 @@ int API_EXPORTED libusb_get_configuration(libusb_device_handle *dev_handle,
{
int r = LIBUSB_ERROR_NOT_SUPPORTED;
- usbi_dbg("");
+ usbi_dbg(" ");
if (usbi_backend.get_configuration)
r = usbi_backend.get_configuration(dev_handle, config);
@@ -1844,7 +1844,7 @@ int API_EXPORTED libusb_clear_halt(libusb_device_handle *dev_handle,
*/
int API_EXPORTED libusb_reset_device(libusb_device_handle *dev_handle)
{
- usbi_dbg("");
+ usbi_dbg(" ");
if (!dev_handle->dev->attached)
return LIBUSB_ERROR_NO_DEVICE;
@@ -2368,7 +2368,7 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
struct timeval tv = { 0, 0 };
int destroying_default_context = 0;
- usbi_dbg("");
+ usbi_dbg(" ");
USBI_GET_CONTEXT(ctx);
/* if working with default context, only actually do the deinitialization
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 53905e6..53d1f6f 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -543,7 +543,7 @@ int usbi_device_cache_descriptor(libusb_device *dev)
int API_EXPORTED libusb_get_device_descriptor(libusb_device *dev,
struct libusb_device_descriptor *desc)
{
- usbi_dbg("");
+ usbi_dbg(" ");
memcpy((unsigned char *) desc, (unsigned char *) &dev->device_descriptor,
sizeof (dev->device_descriptor));
return 0;
diff --git a/libusb/io.c b/libusb/io.c
index 978b09a..77a048f 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1330,7 +1330,7 @@ static int disarm_timerfd(struct libusb_context *ctx)
const struct itimerspec disarm_timer = { { 0, 0 }, { 0, 0 } };
int r;
- usbi_dbg("");
+ usbi_dbg(" ");
r = timerfd_settime(ctx->timerfd, 0, &disarm_timer, NULL);
if (r < 0)
return LIBUSB_ERROR_OTHER;
@@ -1912,7 +1912,7 @@ void API_EXPORTED libusb_interrupt_event_handler(libusb_context *ctx)
int pending_events;
USBI_GET_CONTEXT(ctx);
- usbi_dbg("");
+ usbi_dbg(" ");
usbi_mutex_lock(&ctx->event_data_lock);
pending_events = usbi_pending_events(ctx);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 4150474..8e487b0 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11415
+#define LIBUSB_NANO 11421
--
2.26.1

View File

@ -0,0 +1,53 @@
From d29196dcc4a126dabf7d4131e3843c3b25fe8c35 Mon Sep 17 00:00:00 2001
From: Chris Dickens <christopher.a.dickens@gmail.com>
Date: Mon, 13 Jan 2020 14:07:31 -0800
Subject: [PATCH 08/10] core: Fix libusb_get_max_iso_packet_size() for
superspeed plus
The current logic fails to consider superspeed plus devices properly.
Fix this by checking for superspeed or greater instead of matching
against superspeed.
Closes #553
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
(cherry picked from commit dbd4991a2478ae57e39347bf8610e636554e4c1f)
---
libusb/core.c | 6 +++---
libusb/version_nano.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/libusb/core.c b/libusb/core.c
index 0048dad..5c0a2e0 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -1121,8 +1121,8 @@ int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev,
goto out;
}
- speed = libusb_get_device_speed( dev );
- if (speed == LIBUSB_SPEED_SUPER) {
+ speed = libusb_get_device_speed(dev);
+ if (speed >= LIBUSB_SPEED_SUPER) {
r = libusb_get_ss_endpoint_companion_descriptor(dev->ctx, ep, &ss_ep_cmp);
if (r == LIBUSB_SUCCESS) {
r = ss_ep_cmp->wBytesPerInterval;
@@ -1131,7 +1131,7 @@ int API_EXPORTED libusb_get_max_iso_packet_size(libusb_device *dev,
}
/* If the device isn't a SuperSpeed device or retrieving the SS endpoint didn't worked. */
- if (speed != LIBUSB_SPEED_SUPER || r < 0) {
+ if (speed < LIBUSB_SPEED_SUPER || r < 0) {
val = ep->wMaxPacketSize;
ep_type = (enum libusb_transfer_type) (ep->bmAttributes & 0x3);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 8e487b0..57c2b1d 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11421
+#define LIBUSB_NANO 11426
--
2.26.1

View File

@ -0,0 +1,80 @@
From d414a9c447c79b0e39587998f71f8576605b4fb4 Mon Sep 17 00:00:00 2001
From: Chris Dickens <christopher.a.dickens@gmail.com>
Date: Mon, 13 Jan 2020 15:05:00 -0800
Subject: [PATCH 09/10] core: Do not attempt to destroy a default context that
doesn't exist
Calling libusb_exit(NULL) when a successful call to libusb_init(NULL)
has not been made results in a segmentation violation. This is
definitely a user error, but we can easily guard against it.
Closes #511
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
(cherry picked from commit a5624b22267ec0e146825d3fe94d9e4b2f5ae503)
---
libusb/core.c | 16 +++++++++++-----
libusb/version_nano.h | 2 +-
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/libusb/core.c b/libusb/core.c
index 5c0a2e0..26df871 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2305,7 +2305,7 @@ int API_EXPORTED libusb_init(libusb_context **context)
usbi_mutex_static_lock(&active_contexts_lock);
if (first_init) {
first_init = 0;
- list_init (&active_contexts_list);
+ list_init(&active_contexts_list);
}
list_add (&ctx->list, &active_contexts_list);
usbi_mutex_static_unlock(&active_contexts_lock);
@@ -2337,7 +2337,7 @@ err_free_ctx:
}
usbi_mutex_static_lock(&active_contexts_lock);
- list_del (&ctx->list);
+ list_del(&ctx->list);
usbi_mutex_static_unlock(&active_contexts_lock);
usbi_mutex_lock(&ctx->usb_devs_lock);
@@ -2375,6 +2375,12 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
* if we're the last user */
usbi_mutex_static_lock(&default_context_lock);
if (ctx == usbi_default_context) {
+ if (!usbi_default_context) {
+ usbi_dbg("no default context, not initialized?");
+ usbi_mutex_static_unlock(&default_context_lock);
+ return;
+ }
+
if (--default_context_refcnt > 0) {
usbi_dbg("not destroying default context");
usbi_mutex_static_unlock(&default_context_lock);
@@ -2390,12 +2396,12 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
*/
destroying_default_context = 1;
} else {
- // Unlock default context, as we're not modifying it.
+ /* Unlock default context, as we're not modifying it. */
usbi_mutex_static_unlock(&default_context_lock);
- }
+ }
usbi_mutex_static_lock(&active_contexts_lock);
- list_del (&ctx->list);
+ list_del(&ctx->list);
usbi_mutex_static_unlock(&active_contexts_lock);
if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 57c2b1d..3247cec 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11426
+#define LIBUSB_NANO 11427
--
2.26.1

View File

@ -0,0 +1,264 @@
From e0a164b50a1f11ead9f47da0233f6f954e04127f Mon Sep 17 00:00:00 2001
From: Chris Dickens <christopher.a.dickens@gmail.com>
Date: Thu, 16 Jan 2020 14:17:12 -0800
Subject: [PATCH 10/10] linux_usbfs: Wait until all URBs have been reaped
before freeing them
Prior to this change, the URBs allocated for an individual transfer were
freed when the last URB in the transfer was reaped. Normally this causes
no issues because URBs are reaped in the order they were submitted. If
the device is disconnected while multiple URBs are queued, these URBs
may be reaped in an order that does not match that of submission.
Change the logic to free the URBs when all the URBs of a transfer have
been reaped rather than the last one. While in here, improve some debug
messages.
Closes #607
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
(cherry picked from commit 9eda802d947d9c4212eb3f821fa51956029dade0)
---
libusb/os/linux_usbfs.c | 60 ++++++++++++++++++++---------------------
libusb/version_nano.h | 2 +-
2 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 53530cd..4179b9a 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -944,7 +944,7 @@ static int usbfs_get_active_config(struct libusb_device *dev, int fd)
/* we hit this error path frequently with buggy devices :( */
usbi_warn(DEVICE_CTX(dev),
- "get_configuration failed ret=%d errno=%d", r, errno);
+ "get configuration failed, errno=%d", errno);
priv->active_config = -1;
} else {
if (active_config > 0) {
@@ -1401,7 +1401,7 @@ static int initialize_handle(struct libusb_device_handle *handle, int fd)
if (errno == ENOTTY)
usbi_dbg("getcap not available");
else
- usbi_err(HANDLE_CTX(handle), "getcap failed (%d)", errno);
+ usbi_err(HANDLE_CTX(handle), "getcap failed, errno=%d", errno);
hpriv->caps = 0;
if (supports_flag_zero_packet)
hpriv->caps |= USBFS_CAP_ZERO_PACKET;
@@ -1426,7 +1426,7 @@ static int op_wrap_sys_device(struct libusb_context *ctx,
if (r < 0) {
r = ioctl(fd, IOCTL_USBFS_CONNECTINFO, &ci);
if (r < 0) {
- usbi_err(ctx, "connectinfo failed (%d)", errno);
+ usbi_err(ctx, "connectinfo failed, errno=%d", errno);
return LIBUSB_ERROR_IO;
}
/* There is no ioctl to get the bus number. We choose 0 here
@@ -1537,7 +1537,8 @@ static int op_set_configuration(struct libusb_device_handle *handle, int config)
else if (errno == ENODEV)
return LIBUSB_ERROR_NO_DEVICE;
- usbi_err(HANDLE_CTX(handle), "failed, error %d errno %d", r, errno);
+ usbi_err(HANDLE_CTX(handle),
+ "set configuration failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
@@ -1560,7 +1561,7 @@ static int claim_interface(struct libusb_device_handle *handle, int iface)
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "claim interface failed, error %d errno %d", r, errno);
+ "claim interface failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return 0;
@@ -1575,7 +1576,7 @@ static int release_interface(struct libusb_device_handle *handle, int iface)
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "release interface failed, error %d errno %d", r, errno);
+ "release interface failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return 0;
@@ -1598,7 +1599,7 @@ static int op_set_interface(struct libusb_device_handle *handle, int iface,
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "setintf failed error %d errno %d", r, errno);
+ "set interface failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
@@ -1618,7 +1619,7 @@ static int op_clear_halt(struct libusb_device_handle *handle,
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "clear_halt failed error %d errno %d", r, errno);
+ "clear halt failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
@@ -1650,7 +1651,7 @@ static int op_reset_device(struct libusb_device_handle *handle)
}
usbi_err(HANDLE_CTX(handle),
- "reset failed error %d errno %d", r, errno);
+ "reset failed, errno=%d", errno);
ret = LIBUSB_ERROR_OTHER;
goto out;
}
@@ -1708,7 +1709,7 @@ static int do_streams_ioctl(struct libusb_device_handle *handle, long req,
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "streams-ioctl failed error %d errno %d", r, errno);
+ "streams-ioctl failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
return r;
@@ -1770,7 +1771,7 @@ static int op_kernel_driver_active(struct libusb_device_handle *handle,
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "get driver failed error %d errno %d", r, errno);
+ "get driver failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
@@ -1804,7 +1805,7 @@ static int op_detach_kernel_driver(struct libusb_device_handle *handle,
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(HANDLE_CTX(handle),
- "detach failed error %d errno %d", r, errno);
+ "detach failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
}
@@ -1834,7 +1835,7 @@ static int op_attach_kernel_driver(struct libusb_device_handle *handle,
return LIBUSB_ERROR_BUSY;
usbi_err(HANDLE_CTX(handle),
- "attach failed error %d errno %d", r, errno);
+ "attach failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
} else if (r == 0) {
return LIBUSB_ERROR_NOT_FOUND;
@@ -1863,7 +1864,7 @@ static int detach_kernel_driver_and_claim(struct libusb_device_handle *handle,
return LIBUSB_ERROR_NO_DEVICE;
}
usbi_err(HANDLE_CTX(handle),
- "disconnect-and-claim failed errno %d", errno);
+ "disconnect-and-claim failed, errno=%d", errno);
return LIBUSB_ERROR_OTHER;
} else if (r == 0)
return 0;
@@ -2083,7 +2084,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer)
r = LIBUSB_ERROR_NO_MEM;
} else {
usbi_err(TRANSFER_CTX(transfer),
- "submiturb failed error %d errno=%d", r, errno);
+ "submiturb failed, errno=%d", errno);
r = LIBUSB_ERROR_IO;
}
@@ -2241,7 +2242,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
r = LIBUSB_ERROR_INVALID_PARAM;
} else {
usbi_err(TRANSFER_CTX(transfer),
- "submiturb failed error %d errno=%d", r, errno);
+ "submiturb failed, errno=%d", errno);
r = LIBUSB_ERROR_IO;
}
@@ -2316,7 +2317,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer)
return LIBUSB_ERROR_NO_DEVICE;
usbi_err(TRANSFER_CTX(transfer),
- "submiturb failed error %d errno=%d", r, errno);
+ "submiturb failed, errno=%d", errno);
return LIBUSB_ERROR_IO;
}
return 0;
@@ -2498,10 +2499,10 @@ static int handle_bulk_completion(struct usbi_transfer *itransfer,
goto cancel_remaining;
}
- /* if we're the last urb or we got less data than requested then we're
+ /* if we've reaped all urbs or we got less data than requested then we're
* done */
- if (urb_idx == tpriv->num_urbs - 1) {
- usbi_dbg("last URB in transfer --> complete!");
+ if (tpriv->num_retired == tpriv->num_urbs) {
+ usbi_dbg("all URBs in transfer reaped --> complete!");
goto completed;
} else if (urb->actual_length < urb->buffer_length) {
usbi_dbg("short transfer %d/%d --> complete!",
@@ -2577,15 +2578,15 @@ static int handle_iso_completion(struct usbi_transfer *itransfer,
break;
case -ENODEV:
case -ESHUTDOWN:
- usbi_dbg("device removed");
+ usbi_dbg("packet %d - device removed", i);
lib_desc->status = LIBUSB_TRANSFER_NO_DEVICE;
break;
case -EPIPE:
- usbi_dbg("detected endpoint stall");
+ usbi_dbg("packet %d - detected endpoint stall", i);
lib_desc->status = LIBUSB_TRANSFER_STALL;
break;
case -EOVERFLOW:
- usbi_dbg("overflow error");
+ usbi_dbg("packet %d - overflow error", i);
lib_desc->status = LIBUSB_TRANSFER_OVERFLOW;
break;
case -ETIME:
@@ -2594,12 +2595,12 @@ static int handle_iso_completion(struct usbi_transfer *itransfer,
case -ECOMM:
case -ENOSR:
case -EXDEV:
- usbi_dbg("low-level USB error %d", urb_desc->status);
+ usbi_dbg("packet %d - low-level USB error %d", i, urb_desc->status);
lib_desc->status = LIBUSB_TRANSFER_ERROR;
break;
default:
usbi_warn(TRANSFER_CTX(transfer),
- "unrecognised urb status %d", urb_desc->status);
+ "packet %d - unrecognised urb status %d", i, urb_desc->status);
lib_desc->status = LIBUSB_TRANSFER_ERROR;
break;
}
@@ -2643,9 +2644,9 @@ static int handle_iso_completion(struct usbi_transfer *itransfer,
break;
}
- /* if we're the last urb then we're done */
- if (urb_idx == num_urbs) {
- usbi_dbg("last URB in transfer --> complete!");
+ /* if we've reaped all urbs then we're done */
+ if (tpriv->num_retired == num_urbs) {
+ usbi_dbg("all URBs in transfer reaped --> complete!");
free_iso_urbs(tpriv);
usbi_mutex_unlock(&itransfer->lock);
return usbi_handle_transfer_completion(itransfer, status);
@@ -2733,8 +2734,7 @@ static int reap_for_handle(struct libusb_device_handle *handle)
if (errno == ENODEV)
return LIBUSB_ERROR_NO_DEVICE;
- usbi_err(HANDLE_CTX(handle), "reap failed error %d errno=%d",
- r, errno);
+ usbi_err(HANDLE_CTX(handle), "reap failed, errno=%d", errno);
return LIBUSB_ERROR_IO;
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 3247cec..f496998 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11427
+#define LIBUSB_NANO 11428
--
2.26.1

View File

@ -0,0 +1,47 @@
From 5466375683a48bd650091781991d9e4facd06ba6 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Fri, 26 Jun 2020 21:35:46 +0300
Subject: [PATCH] Downstream: fix covscan issue: close(fd) called twice
Seems it's already fixed upstream, but by several commits, that
change more things.
This simple patch, just prevents the case of calling close(fd) twice
Warning is:
Error: USE_AFTER_FREE (CWE-416): [#def2]
libusb-1.0.23/libusb/os/linux_usbfs.c:1043: closed_arg: "close(int)" closes "fd".
libusb-1.0.23/libusb/os/linux_usbfs.c:1054: double_close: Calling "close(int)"
closes handle "fd" which has already been closed.
---
libusb/os/linux_usbfs.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 4179b9a..537f0dd 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -1039,8 +1039,10 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
priv->descriptors_len += r;
} while (priv->descriptors_len == descriptors_size);
- if (fd != wrapped_fd)
+ if (fd != wrapped_fd) {
close(fd);
+ fd = -1;
+ }
if (priv->descriptors_len < DEVICE_DESC_LENGTH) {
usbi_err(ctx, "short descriptor read (%d)",
@@ -1050,7 +1052,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
if (sysfs_dir && sysfs_can_relate_devices)
{
- if (fd != wrapped_fd)
+ if ((fd >= 0) && (fd != wrapped_fd))
close(fd);
return LIBUSB_SUCCESS;
}
--
2.26.2

View File

@ -1,822 +0,0 @@
From 20b8e95bfc3a9c1be1752e65043a8ed9445fbbd2 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 15 Jul 2021 17:07:09 +0200
Subject: [PATCH 01/18] examples: Fix warning about uninitlised variable
---
examples/fxload.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/examples/fxload.c b/examples/fxload.c
index 541c3d3a3..85df69952 100644
--- a/examples/fxload.c
+++ b/examples/fxload.c
@@ -87,7 +87,8 @@ int main(int argc, char*argv[])
const char *type = NULL;
const char *fx_name[FX_TYPE_MAX] = FX_TYPE_NAMES;
const char *ext, *img_name[] = IMG_TYPE_NAMES;
- int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)];
+ int fx_type = FX_TYPE_UNDEFINED;
+ int img_type[ARRAYSIZE(path)] = { IMG_TYPE_UNDEFINED, IMG_TYPE_UNDEFINED };
int opt, status;
unsigned int i, j;
unsigned vid = 0, pid = 0;
From 0803cdc46314c70ad7f12a7c2d0b1df5b028a89d Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 15 Jul 2021 17:08:12 +0200
Subject: [PATCH 02/18] core: Add non-null annotations to avoid static analyser
warnings
It is only valid to call these inline functions with non-null values.
However, static analysis may complain that the functions may dereference
the pointer incorrectly if it is only looking at the function itself
rather than including the surrounding code.
Add the appropriate annotiations to both fix warnings and improve
detection of bugs in API users.
---
libusb/libusb.h | 13 +++++++++++++
libusb/libusbi.h | 14 ++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 61cacc95a..ea09fa8d9 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -77,8 +77,10 @@ typedef SSIZE_T ssize_t;
#if defined(__GNUC__)
#define LIBUSB_PACKED __attribute__ ((packed))
+#define LIBUSB_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
#else
#define LIBUSB_PACKED
+#define LIBUSB_NONNULL(...)
#endif /* __GNUC__ */
/** \def LIBUSB_CALL
@@ -1479,6 +1481,7 @@ int LIBUSB_CALL libusb_set_auto_detach_kernel_driver(
* \param transfer a transfer
* \returns pointer to the first byte of the data section
*/
+LIBUSB_NONNULL(1)
static inline unsigned char *libusb_control_transfer_get_data(
struct libusb_transfer *transfer)
{
@@ -1497,6 +1500,7 @@ static inline unsigned char *libusb_control_transfer_get_data(
* \param transfer a transfer
* \returns a casted pointer to the start of the transfer data buffer
*/
+LIBUSB_NONNULL(1)
static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
struct libusb_transfer *transfer)
{
@@ -1526,6 +1530,7 @@ static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
* \ref libusb_control_setup::wLength "wLength" field of
* \ref libusb_control_setup
*/
+LIBUSB_NONNULL(1)
static inline void libusb_fill_control_setup(unsigned char *buffer,
uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
uint16_t wLength)
@@ -1575,6 +1580,7 @@ uint32_t LIBUSB_CALL libusb_transfer_get_stream_id(
* \param user_data user data to pass to callback function
* \param timeout timeout for the transfer in milliseconds
*/
+LIBUSB_NONNULL(1)
static inline void libusb_fill_control_transfer(
struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
@@ -1606,6 +1612,7 @@ static inline void libusb_fill_control_transfer(
* \param user_data user data to pass to callback function
* \param timeout timeout for the transfer in milliseconds
*/
+LIBUSB_NONNULL(1)
static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
libusb_device_handle *dev_handle, unsigned char endpoint,
unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
@@ -1637,6 +1644,7 @@ static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
* \param user_data user data to pass to callback function
* \param timeout timeout for the transfer in milliseconds
*/
+LIBUSB_NONNULL(1)
static inline void libusb_fill_bulk_stream_transfer(
struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
unsigned char endpoint, uint32_t stream_id,
@@ -1662,6 +1670,7 @@ static inline void libusb_fill_bulk_stream_transfer(
* \param user_data user data to pass to callback function
* \param timeout timeout for the transfer in milliseconds
*/
+LIBUSB_NONNULL(1)
static inline void libusb_fill_interrupt_transfer(
struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *buffer, int length,
@@ -1691,6 +1700,7 @@ static inline void libusb_fill_interrupt_transfer(
* \param user_data user data to pass to callback function
* \param timeout timeout for the transfer in milliseconds
*/
+LIBUSB_NONNULL(1)
static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
libusb_device_handle *dev_handle, unsigned char endpoint,
unsigned char *buffer, int length, int num_iso_packets,
@@ -1715,6 +1725,7 @@ static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
* \param length the length to set in each isochronous packet descriptor
* \see libusb_get_max_packet_size()
*/
+LIBUSB_NONNULL(1)
static inline void libusb_set_iso_packet_lengths(
struct libusb_transfer *transfer, unsigned int length)
{
@@ -1740,6 +1751,7 @@ static inline void libusb_set_iso_packet_lengths(
* or NULL if the packet does not exist.
* \see libusb_get_iso_packet_buffer_simple()
*/
+LIBUSB_NONNULL(1)
static inline unsigned char *libusb_get_iso_packet_buffer(
struct libusb_transfer *transfer, unsigned int packet)
{
@@ -1782,6 +1794,7 @@ static inline unsigned char *libusb_get_iso_packet_buffer(
* or NULL if the packet does not exist.
* \see libusb_get_iso_packet_buffer()
*/
+LIBUSB_NONNULL(1)
static inline unsigned char *libusb_get_iso_packet_buffer_simple(
struct libusb_transfer *transfer, unsigned int packet)
{
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index b1fc88c99..db074160c 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -192,11 +192,13 @@ struct list_head {
#define list_empty(entry) ((entry)->next == (entry))
+LIBUSB_NONNULL(1)
static inline void list_init(struct list_head *entry)
{
entry->prev = entry->next = entry;
}
+LIBUSB_NONNULL(1, 2)
static inline void list_add(struct list_head *entry, struct list_head *head)
{
entry->next = head->next;
@@ -206,6 +208,7 @@ static inline void list_add(struct list_head *entry, struct list_head *head)
head->next = entry;
}
+LIBUSB_NONNULL(1, 2)
static inline void list_add_tail(struct list_head *entry,
struct list_head *head)
{
@@ -216,6 +219,7 @@ static inline void list_add_tail(struct list_head *entry,
head->prev = entry;
}
+LIBUSB_NONNULL(1)
static inline void list_del(struct list_head *entry)
{
entry->next->prev = entry->prev;
@@ -223,6 +227,7 @@ static inline void list_del(struct list_head *entry)
entry->next = entry->prev = NULL;
}
+LIBUSB_NONNULL(1, 2)
static inline void list_cut(struct list_head *list, struct list_head *head)
{
if (list_empty(head)) {
@@ -773,10 +778,10 @@ struct usbi_hotplug_message {
/* shared data and functions */
-void usbi_hotplug_init(struct libusb_context *ctx);
-void usbi_hotplug_exit(struct libusb_context *ctx);
+void usbi_hotplug_init(struct libusb_context *ctx) LIBUSB_NONNULL(1);
+void usbi_hotplug_exit(struct libusb_context *ctx) LIBUSB_NONNULL(1);
void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev,
- libusb_hotplug_event event);
+ libusb_hotplug_event event) LIBUSB_NONNULL(1);
void usbi_hotplug_process(struct libusb_context *ctx, struct list_head *hotplug_msgs);
int usbi_io_init(struct libusb_context *ctx);
@@ -807,7 +812,8 @@ struct usbi_event_source {
int usbi_add_event_source(struct libusb_context *ctx, usbi_os_handle_t os_handle,
short poll_events);
-void usbi_remove_event_source(struct libusb_context *ctx, usbi_os_handle_t os_handle);
+void usbi_remove_event_source(struct libusb_context *ctx, usbi_os_handle_t os_handle)
+ LIBUSB_NONNULL(1);
struct usbi_option {
int is_set;
From 3ba52d0d048214ee530c2343260965724291255a Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:21:09 +0100
Subject: [PATCH 03/18] core: Silence dereference warnings using assertions in
list_del
It is guaranteed that entry->next and entry->prev are non-null for a
list item that is part of a list. The static analyser might be confused
though, so add an appropriate assert in case debug mode is enabled.
---
libusb/libusbi.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index db074160c..27de77aa9 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -222,6 +222,10 @@ static inline void list_add_tail(struct list_head *entry,
LIBUSB_NONNULL(1)
static inline void list_del(struct list_head *entry)
{
+#ifndef NDEBUG
+ assert(entry->next && entry->prev);
+#endif
+
entry->next->prev = entry->prev;
entry->prev->next = entry->next;
entry->next = entry->prev = NULL;
From 70486056d5668c94ea3a1824541ff2f36f378d3e Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 15 Jul 2021 17:11:41 +0200
Subject: [PATCH 04/18] core: Fix incorrect free if reallocating to zero size
A realloc to a size of 0 is equivalent to a free call. As such, in that
case free'ing the original pointer would result in a double free. Fix
this by adding a check that the new size if larger than zero.
---
libusb/libusbi.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 27de77aa9..dabf77a9d 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -257,7 +257,14 @@ static inline void list_splice_front(struct list_head *list, struct list_head *h
static inline void *usbi_reallocf(void *ptr, size_t size)
{
- void *ret = realloc(ptr, size);
+ void *ret;
+
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ }
+
+ ret = realloc(ptr, size);
if (!ret)
free(ptr);
From 73f565261d9284d9f6b0081e3e23fd49773f53c7 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 15 Jul 2021 17:13:18 +0200
Subject: [PATCH 05/18] linux_usbfs: Work around static analyser thinking fd is
leaked
Static analysis using coverity is detecting the file descriptor handle
potentially being leaked in some situations. The code itself is actually
sound, but coverity is not correctly following the fact that fd can be
compared against wrapped_fd.
Fix this by introducing an fd_close variable which is compared to a
fixed value to decide whether to close the fd. Also switch to a goto
pattern rather than returning from different places.
---
libusb/os/linux_usbfs.c | 51 ++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 21 deletions(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 285d9caa7..1799a9ea0 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -904,7 +904,8 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
struct linux_device_priv *priv = usbi_get_device_priv(dev);
struct libusb_context *ctx = DEVICE_CTX(dev);
size_t alloc_len;
- int fd, speed, r;
+ int fd, fd_close = -1;
+ int speed, r;
ssize_t nb;
dev->bus_number = busnum;
@@ -934,19 +935,22 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
/* cache descriptors in memory */
if (sysfs_dir) {
- fd = open_sysfs_attr(ctx, sysfs_dir, "descriptors");
+ fd = fd_close = open_sysfs_attr(ctx, sysfs_dir, "descriptors");
} else if (wrapped_fd < 0) {
- fd = get_usbfs_fd(dev, O_RDONLY, 0);
+ fd = fd_close = get_usbfs_fd(dev, O_RDONLY, 0);
} else {
fd = wrapped_fd;
r = lseek(fd, 0, SEEK_SET);
if (r < 0) {
usbi_err(ctx, "lseek failed, errno=%d", errno);
- return LIBUSB_ERROR_IO;
+ r = LIBUSB_ERROR_IO;
+ goto out;
}
}
- if (fd < 0)
- return fd;
+ if (fd < 0) {
+ r = fd;
+ goto out;
+ }
alloc_len = 0;
do {
@@ -956,9 +960,8 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
alloc_len += desc_read_length;
priv->descriptors = usbi_reallocf(priv->descriptors, alloc_len);
if (!priv->descriptors) {
- if (fd != wrapped_fd)
- close(fd);
- return LIBUSB_ERROR_NO_MEM;
+ r = LIBUSB_ERROR_NO_MEM;
+ goto out;
}
read_ptr = (uint8_t *)priv->descriptors + priv->descriptors_len;
/* usbfs has holes in the file */
@@ -967,36 +970,39 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
nb = read(fd, read_ptr, desc_read_length);
if (nb < 0) {
usbi_err(ctx, "read descriptor failed, errno=%d", errno);
- if (fd != wrapped_fd)
- close(fd);
- return LIBUSB_ERROR_IO;
+ r = LIBUSB_ERROR_IO;
+ goto out;
}
priv->descriptors_len += (size_t)nb;
} while (priv->descriptors_len == alloc_len);
- if (fd != wrapped_fd)
- close(fd);
+ if (fd_close >= 0) {
+ close(fd_close);
+ fd_close = -1;
+ }
if (priv->descriptors_len < LIBUSB_DT_DEVICE_SIZE) {
usbi_err(ctx, "short descriptor read (%zu)", priv->descriptors_len);
- return LIBUSB_ERROR_IO;
+ r = LIBUSB_ERROR_IO;
+ goto out;
}
r = parse_config_descriptors(dev);
if (r < 0)
- return r;
+ goto out;
memcpy(&dev->device_descriptor, priv->descriptors, LIBUSB_DT_DEVICE_SIZE);
if (sysfs_dir) {
/* sysfs descriptors are in bus-endian format */
usbi_localize_device_descriptor(&dev->device_descriptor);
- return LIBUSB_SUCCESS;
+ r = LIBUSB_SUCCESS;
+ goto out;
}
/* cache active config */
if (wrapped_fd < 0)
- fd = get_usbfs_fd(dev, O_RDWR, 1);
+ fd = fd_close = get_usbfs_fd(dev, O_RDWR, 1);
else
fd = wrapped_fd;
if (fd < 0) {
@@ -1009,12 +1015,15 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
else
priv->active_config = -1; /* No config dt */
- return LIBUSB_SUCCESS;
+ r = LIBUSB_SUCCESS;
+ goto out;
}
r = usbfs_get_active_config(dev, fd);
- if (fd != wrapped_fd)
- close(fd);
+
+out:
+ if (fd_close >= 0)
+ close(fd_close);
return r;
}
From f6cc8938c5ccf3556cfa54fe8e1d26e627995731 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:08:31 +0100
Subject: [PATCH 06/18] examples: Fix warning about NULL pointer dereference
It seems like coverity is getting confused by the transfers being global
variables, thinking that img_transfer may become NULL again.
Fix this bogus warning by moving the check down.
---
examples/dpfp.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/examples/dpfp.c b/examples/dpfp.c
index 682865053..4a871ee4f 100644
--- a/examples/dpfp.c
+++ b/examples/dpfp.c
@@ -554,13 +554,8 @@ static int do_init(void)
static int alloc_transfers(void)
{
img_transfer = libusb_alloc_transfer(0);
- if (!img_transfer) {
- errno = ENOMEM;
- return -1;
- }
-
irq_transfer = libusb_alloc_transfer(0);
- if (!irq_transfer) {
+ if (!img_transfer || !irq_transfer) {
errno = ENOMEM;
return -1;
}
From c2257799e48351e4ac09bb40794f3c8559d93459 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:09:53 +0100
Subject: [PATCH 07/18] examples: Assert the data fits into our static buffer
---
examples/ezusb.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/examples/ezusb.c b/examples/ezusb.c
index 4bed12a4c..0ea787190 100644
--- a/examples/ezusb.c
+++ b/examples/ezusb.c
@@ -23,6 +23,7 @@
#include <config.h>
+#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@@ -303,6 +304,7 @@ static int parse_ihex(FILE *image, void *context,
buf[3] = 0;
len = strtoul(buf+1, NULL, 16);
buf[3] = tmp;
+ assert(len <= sizeof(data));
/* Read the target offset (address up to 64KB) */
tmp = buf[7];
From 9bd8bca34de151e191db4d33d717a36488f9a96e Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:11:28 +0100
Subject: [PATCH 08/18] core: Tell coverity that libusb_open does not free
Internally, libusb_open does an unref in an error case. coverity doesn't
seem to notice that this is balanced with the earlier ref, and thinks
that the passed in device may be free'ed. Annotate the function to
prevent misdetections.
An alternative would be to only take the reference after checking for
the error, but the code is idiomatic as-is.
---
libusb/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libusb/core.c b/libusb/core.c
index ec429b7cf..b9bf844ee 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -1294,6 +1294,7 @@ int API_EXPORTED libusb_wrap_sys_device(libusb_context *ctx, intptr_t sys_dev,
* \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
* \returns another LIBUSB_ERROR code on other failure
*/
+/* coverity[-free: arg-0] false positive due to error handling path */
int API_EXPORTED libusb_open(libusb_device *dev,
libusb_device_handle **dev_handle)
{
From 88e1269900cb8a581d6335d758b713d71ecd8d8e Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:13:26 +0100
Subject: [PATCH 09/18] core: Remove unneeded bounds check
This makes the code slightly less efficient, but shuts up warnings that
the later switch ends up with dead error handling code.
---
libusb/core.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libusb/core.c b/libusb/core.c
index b9bf844ee..1643f9334 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2202,10 +2202,6 @@ int API_EXPORTED libusb_set_option(libusb_context *ctx,
return r;
}
- if (option >= LIBUSB_OPTION_MAX) {
- return LIBUSB_ERROR_INVALID_PARAM;
- }
-
if (NULL == ctx) {
usbi_mutex_static_lock(&default_context_lock);
default_context_options[option].is_set = 1;
From 1eb546e65aaca0c47615a275a961bbeb123c838e Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:15:16 +0100
Subject: [PATCH 10/18] descriptor: Avoid uninitialized memory warnings
The static analyzer has trouble understanding that get_config_descriptor
fills in the config descriptor. Just initializing the memory silences
the warning and is safe to do.
---
libusb/descriptor.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 253ef1c31..dbcf061d9 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -555,7 +555,7 @@ int API_EXPORTED libusb_get_device_descriptor(libusb_device *dev,
int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
struct libusb_config_descriptor **config)
{
- union usbi_config_desc_buf _config;
+ union usbi_config_desc_buf _config = { 0, };
uint16_t config_len;
uint8_t *buf;
int r;
@@ -658,7 +658,7 @@ int API_EXPORTED libusb_get_config_descriptor_by_value(libusb_device *dev,
usbi_dbg(DEVICE_CTX(dev), "value %u", bConfigurationValue);
for (idx = 0; idx < dev->device_descriptor.bNumConfigurations; idx++) {
- union usbi_config_desc_buf _config;
+ union usbi_config_desc_buf _config = { 0, };
r = get_config_descriptor(dev, idx, _config.buf, sizeof(_config.buf));
if (r < 0)
From 0de57c4af4e637a0a8adfda9a907774add81c8ec Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:19:04 +0100
Subject: [PATCH 11/18] io: Suppress invalid free warning from coverity
Coverity is not understanding the pointer arithmetic involved with the
transfer in-memory storage. As such, it flags the free as invalid, even
though everything is fine. Add an appropriate comment to silence the
warning.
---
libusb/io.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libusb/io.c b/libusb/io.c
index b919e9d91..a801ee6aa 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1696,8 +1696,10 @@ int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
transfer->callback(transfer);
/* transfer might have been freed by the above call, do not use from
* this point. */
- if (flags & LIBUSB_TRANSFER_FREE_TRANSFER)
+ if (flags & LIBUSB_TRANSFER_FREE_TRANSFER) {
+ /* coverity[incorrect_free] is reported incorrectly here due to the memory layout */
libusb_free_transfer(transfer);
+ }
return r;
}
From 5dad238771240a6aa8234ba42511fb422c79800c Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:20:27 +0100
Subject: [PATCH 12/18] io: Suppress missing unlock warning from coverity
The function is supposed to take the lock, as such, this is the expected
behaviour.
---
libusb/io.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libusb/io.c b/libusb/io.c
index a801ee6aa..114087d94 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1790,6 +1790,7 @@ int API_EXPORTED libusb_try_lock_events(libusb_context *ctx)
return 1;
ctx->event_handler_active = 1;
+ /* coverity[missing_unlock] is expected here */
return 0;
}
From 884b55a36ae4dfae6fda1120c948bcf17a333b95 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:23:45 +0100
Subject: [PATCH 13/18] events_posix: Silence warnings about zero-allocated
memory
The static analyser got confused by the fact that fds may be NULL if
there are no event sources. Obviously, in that case the later loop that
dereferences fds will never do anything, but coverity seems to miss that
part.
Silence the warning by doing an early return from the function.
---
libusb/os/events_posix.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libusb/os/events_posix.c b/libusb/os/events_posix.c
index 715a2d551..172f8afe8 100644
--- a/libusb/os/events_posix.c
+++ b/libusb/os/events_posix.c
@@ -201,6 +201,10 @@ int usbi_alloc_event_data(struct libusb_context *ctx)
for_each_event_source(ctx, ievent_source)
ctx->event_data_cnt++;
+ /* Silence warning about use of zero allocated memory. */
+ if (ctx->event_data_cnt == 0)
+ return 0;
+
fds = calloc(ctx->event_data_cnt, sizeof(*fds));
if (!fds)
return LIBUSB_ERROR_NO_MEM;
From 4e2589b2e9981e5213fb4267550c10638f758add Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:25:40 +0100
Subject: [PATCH 14/18] linux_usbfs: Disable sleep workaround when using udev
The workaround to sleep 10ms if a device node has not yet been created
is definitely not needed with udev. I am not sure what the race looks
like in the netlink case, unless some other userspace daemon (udev) is
reacting to the same message and creates the device.
I suppose, in the long run this might be fixed by removing the netlink
code.
---
libusb/os/linux_usbfs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 1799a9ea0..481eff6ef 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -197,6 +197,8 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
if (fd != -1)
return fd; /* Success */
+/* This workaround is only relevant when watching netlink directly rather than udev. */
+#if !defined(HAVE_LIBUDEV)
if (errno == ENOENT) {
const long delay_ms = 10L;
const struct timespec delay_ts = { 0L, delay_ms * 1000L * 1000L };
@@ -211,6 +213,7 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
if (fd != -1)
return fd; /* Success */
}
+#endif
if (!silent) {
usbi_err(ctx, "libusb couldn't open USB device %s, errno=%d", path, errno);
From d237b8cca6c33e237da69ee096232d216f9202a8 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:29:35 +0100
Subject: [PATCH 15/18] linux_usbfs: Silence coverity warnings about returned
offset
The seek_to_next_config function returns an offset. This was marked as
tained by coverity, but really, we can trust it to be OK in the
surrounding code. Mark the return value to silence the warnings.
---
libusb/os/linux_usbfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 481eff6ef..d95ed3bea 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -638,6 +638,7 @@ int linux_get_device_address(struct libusb_context *ctx, int detached,
}
/* Return offset of the next config descriptor */
+/* coverity[-taint_source] as the returned offset can be trusted */
static int seek_to_next_config(struct libusb_context *ctx,
uint8_t *buffer, size_t len)
{
From ea73414f3309a908d2819991580b080cabca17eb Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Wed, 9 Feb 2022 19:31:44 +0100
Subject: [PATCH 16/18] linux_usbfs: Silence coverity warning about missing
locking
The reap_status field is locked in most cases when it is accessed.
This causes a warning from coverity, however locking is not needed in
this particular case as the transfer has not yet been submitted.
As such, add an appropriate comment to silence the warning.
---
libusb/os/linux_usbfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index d95ed3bea..35cc54ab5 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -1984,6 +1984,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer)
tpriv->num_urbs = num_urbs;
tpriv->num_retired = 0;
tpriv->reap_action = NORMAL;
+ /* coverity[missing_lock] as we don't need to lock before submission */
tpriv->reap_status = LIBUSB_TRANSFER_COMPLETED;
for (i = 0; i < num_urbs; i++) {
From 3c792a9b21ec07d9a3f369b9a79eec1e0f999823 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 10 Feb 2022 10:51:11 +0100
Subject: [PATCH 17/18] core: Silence coverity by handling long log messages in
one statement
Having two statements seems to confuse coverity. Having two checks right
after each other doesn't give us anything, so just fold them into one so
that the static analyzer is not getting confused.
---
libusb/core.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/libusb/core.c b/libusb/core.c
index 1643f9334..359500a9a 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2641,16 +2641,13 @@ static void log_v(struct libusb_context *ctx, enum libusb_log_level level,
header_len = 0;
}
- text_len = vsnprintf(buf + header_len, sizeof(buf) - (size_t)header_len,
+ text_len = vsnprintf(buf + header_len,
+ sizeof(buf) - (size_t)header_len - (int)sizeof(USBI_LOG_LINE_END),
format, args);
- if (text_len < 0 || text_len + header_len >= (int)sizeof(buf)) {
+ if (text_len < 0 || text_len + header_len + (int)sizeof(USBI_LOG_LINE_END) >= (int)sizeof(buf)) {
/* Truncated log output. On some platforms a -1 return value means
- * that the output was truncated. */
- text_len = (int)sizeof(buf) - header_len;
- }
- if (header_len + text_len + (int)sizeof(USBI_LOG_LINE_END) >= (int)sizeof(buf)) {
- /* Need to truncate the text slightly to fit on the terminator. */
- text_len -= (header_len + text_len + (int)sizeof(USBI_LOG_LINE_END)) - (int)sizeof(buf);
+ * that the output was truncated (e.g. glibc < 2.1). */
+ text_len = (int)sizeof(buf) - header_len - (int)sizeof(USBI_LOG_LINE_END);
}
strcpy(buf + header_len + text_len, USBI_LOG_LINE_END);
From c6033e4f7f30a0ee1d872dc11ec461b812b5e4e6 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 31 Mar 2022 11:49:11 +0200
Subject: [PATCH 18/18] linux: Avoid NULL pointer dereference warning from gcc
This warning is a false positive. It occurs because the HANDLE_CTX
checks whether the passed device handle is non-NULL, returning NULL if
it is. However, in these cases the handle is guaranteed to not be NULL
and adding an explicit non-NULL check does not avoid the warning.
---
libusb/os/linux_usbfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 35cc54ab5..6e3ea49af 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -1433,7 +1433,7 @@ static void op_close(struct libusb_device_handle *dev_handle)
/* fd may have already been removed by POLLERR condition in op_handle_events() */
if (!hpriv->fd_removed)
- usbi_remove_event_source(HANDLE_CTX(dev_handle), hpriv->fd);
+ usbi_remove_event_source(DEVICE_CTX(dev_handle->dev), hpriv->fd);
if (!hpriv->fd_keep)
close(hpriv->fd);
}
@@ -2736,7 +2736,7 @@ static int op_handle_events(struct libusb_context *ctx,
/* remove the fd from the pollfd set so that it doesn't continuously
* trigger an event, and flag that it has been removed so op_close()
* doesn't try to remove it a second time */
- usbi_remove_event_source(HANDLE_CTX(handle), hpriv->fd);
+ usbi_remove_event_source(DEVICE_CTX(handle->dev), hpriv->fd);
hpriv->fd_removed = 1;
/* device will still be marked as attached if hotplug monitor thread

View File

@ -1,24 +1,34 @@
Summary: Library for accessing USB devices Summary: Library for accessing USB devices
Name: libusbx Name: libusbx
%define upstream 1.0.26 Version: 1.0.23
Version: %( echo %{upstream} | sed s/-/~/ ) Release: 4%{?dist}
Release: 1%{?dist}
# upstream libusbx has merged back with libusb and is now called libusb again # upstream libusbx has merged back with libusb and is now called libusb again
# but we already have a libusb package for the old libusb-compat-0.1, renaming # but we already have a libusb package for the old libusb-compat-0.1, renaming
# that to libusb-compat while at the same time giving this its name is a bit # that to libusb-compat while at the same time giving this its name is a bit
# tricky, lets stick with the libusbx name for now # tricky, lets stick with the libusbx name for now
Source0: https://github.com/libusb/libusb/releases/download/v%{upstream}/libusb-%{upstream}.tar.bz2 Source0: https://github.com/libusb/libusb/archive/v%{version}/libusb-%{version}.tar.gz
Patch0001: 0001-fix-constant-not-in-range-of-enumerated-type.patch
Patch0002: 0002-Doxygen-add-libusb_wrap_sys_device-in-the-API-list.patch
Patch0003: 0003-Linux-backend-fix-ressource-leak.patch
Patch0004: 0004-Linux-Improved-system-out-of-memory-handling.patch
Patch0005: 0005-linux_udev-silently-ignore-bind-action.patch
Patch0006: 0006-Add-Null-POSIX-backend.patch
Patch0007: 0007-core-fix-build-warning-on-newer-versions-of-gcc.patch
Patch0008: 0008-core-Fix-libusb_get_max_iso_packet_size-for-superspe.patch
Patch0009: 0009-core-Do-not-attempt-to-destroy-a-default-context-tha.patch
Patch0010: 0010-linux_usbfs-Wait-until-all-URBs-have-been-reaped-bef.patch
# Downstream only - a simple fix for a covscan issue.
Patch1000: 1000-Downstream-fix-covscan-issue-close-fd-called-twice.patch
License: LGPLv2+ License: LGPLv2+
Group: System Environment/Libraries
URL: http://libusb.info URL: http://libusb.info
BuildRequires: systemd-devel doxygen libtool BuildRequires: systemd-devel doxygen libtool
BuildRequires: make
#BuildRequires: umockdev-devel >= 0.16.0
Provides: libusb1 = %{version}-%{release} Provides: libusb1 = %{version}-%{release}
Obsoletes: libusb1 <= 1.0.9 Obsoletes: libusb1 <= 1.0.9
# Pull in coverity related fixes
Patch9991: https://github.com/libusb/libusb/pull/1067.patch
%description %description
This package provides a way for applications to access USB devices. This package provides a way for applications to access USB devices.
@ -33,6 +43,7 @@ if you need libusb-0.1 compatibility install the libusb package.
%package devel %package devel
Summary: Development files for %{name} Summary: Development files for %{name}
Group: Development/Libraries
Requires: %{name}%{?_isa} = %{version}-%{release} Requires: %{name}%{?_isa} = %{version}-%{release}
Provides: libusb1-devel = %{version}-%{release} Provides: libusb1-devel = %{version}-%{release}
Obsoletes: libusb1-devel <= 1.0.9 Obsoletes: libusb1-devel <= 1.0.9
@ -44,6 +55,7 @@ developing applications that use %{name}.
%package devel-doc %package devel-doc
Summary: Development files for %{name} Summary: Development files for %{name}
Group: Development/Libraries
Provides: libusb1-devel-doc = %{version}-%{release} Provides: libusb1-devel-doc = %{version}-%{release}
Obsoletes: libusb1-devel-doc <= 1.0.9 Obsoletes: libusb1-devel-doc <= 1.0.9
BuildArch: noarch BuildArch: noarch
@ -61,14 +73,15 @@ This package contains tests and examples for %{name}.
%prep %prep
%autosetup -p1 -n libusb-%{upstream} %autosetup -S git_am -n libusb-%{version}
chmod -x examples/*.c chmod -x examples/*.c
mkdir -p m4 mkdir -p m4
autoreconf -ivf
%build %build
%configure --disable-static --enable-examples-build %configure --disable-static --enable-examples-build
%{make_build} make %{?_smp_mflags}
pushd doc pushd doc
make docs make docs
popd popd
@ -78,10 +91,9 @@ popd
%install %install
%{make_install} %make_install
mkdir -p $RPM_BUILD_ROOT%{_bindir} mkdir -p $RPM_BUILD_ROOT%{_bindir}
install -m 755 tests/.libs/stress $RPM_BUILD_ROOT%{_bindir}/libusb-test-stress install -m 755 tests/.libs/stress $RPM_BUILD_ROOT%{_bindir}/libusb-test-stress
#install -m 755 tests/.libs/umockdev $RPM_BUILD_ROOT%{_bindir}/libusb-test-umockdev
install -m 755 examples/.libs/testlibusb \ install -m 755 examples/.libs/testlibusb \
$RPM_BUILD_ROOT%{_bindir}/libusb-test-libusb $RPM_BUILD_ROOT%{_bindir}/libusb-test-libusb
# Some examples are very device-specific / require specific hw and miss --help # Some examples are very device-specific / require specific hw and miss --help
@ -96,7 +108,6 @@ rm $RPM_BUILD_ROOT%{_libdir}/*.la
%check %check
LD_LIBRARY_PATH=libusb/.libs ldd $RPM_BUILD_ROOT%{_bindir}/libusb-test-stress LD_LIBRARY_PATH=libusb/.libs ldd $RPM_BUILD_ROOT%{_bindir}/libusb-test-stress
LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-test-stress LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-test-stress
#LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-test-umockdev
LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-test-libusb LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-test-libusb
LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-example-listdevs LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-example-listdevs
@ -106,7 +117,7 @@ LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-example-listdevs
%files %files
%license COPYING %license COPYING
%doc AUTHORS README ChangeLog %doc AUTHORS README.md ChangeLog
%{_libdir}/*.so.* %{_libdir}/*.so.*
%files devel %files devel
@ -115,80 +126,40 @@ LD_LIBRARY_PATH=libusb/.libs $RPM_BUILD_ROOT%{_bindir}/libusb-example-listdevs
%{_libdir}/pkgconfig/libusb-1.0.pc %{_libdir}/pkgconfig/libusb-1.0.pc
%files devel-doc %files devel-doc
%doc doc/api-1.0 examples/*.c %doc doc/html examples/*.c
%files tests-examples %files tests-examples
%{_bindir}/libusb-example-fxload %{_bindir}/libusb-example-fxload
%{_bindir}/libusb-example-listdevs %{_bindir}/libusb-example-listdevs
%{_bindir}/libusb-example-xusb %{_bindir}/libusb-example-xusb
%{_bindir}/libusb-test-stress %{_bindir}/libusb-test-stress
#%{_bindir}/libusb-test-umockdev
%{_bindir}/libusb-test-libusb %{_bindir}/libusb-test-libusb
%changelog %changelog
* Tue Apr 12 2022 Benjamin Berg <bberg@redhat.com> - 1.0.26 * Wed Aug 12 2020 Victor Toso <victortoso@redhat.com> - 1.0.23-4
- Pull in new upstream libusb containing important regression fixes - Install README.md as README is only a symlink to .md
Resolves: #2058730 Resolves: rhbz#1849682
Resolves: #1938801
* Mon Feb 28 2022 Benjamin Berg <bberg@redhat.com> - 1.0.25-3 * Fri Jun 26 2020 Uri Lublin <uril@redhat.com> - 1.0.23-3
- Updated and new regression fixes - Fix covscan warning
Resolves: #2058730 Related: rhbz#1825941
Related: #1938801
* Tue Feb 15 2022 Benjamin Berg <bberg@redhat.com> - 1.0.25-2 * Thu May 14 2020 Victor Toso <victortoso@redhat.com> - 1.0.23-2
- Fix a crash if a transfer outlives closing the device - Cherry pick a few fixes since 1.0.23 release
Related: #1938801 - Related: rhbz#1825941
* Thu Feb 10 2022 Benjamin Berg <bberg@redhat.com> - 1.0.25-1 * Tue May 05 2020 Victor Toso <victortoso@redhat.com> - 1.0.23-1
- Update to 1.0.25
- Fix a crash after libusb_exit API has been misused
- Add patchset to fix covscan reports
Resolves: #1938801
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 1.0.24-4
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 1.0.24-3
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
* Tue Feb 16 2021 Benjamin Berg <bberg@redhat.com> - 1.0.24-2
- Pull in upstream bugfixes
Resolves: #1929148
* Thu Feb 11 2021 Victor Toso <victortoso@redhat.com> - 1.0.24-1
- Update to 1.0.24
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.23-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.23-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Thu Mar 26 2020 Peter Robinson <pbrobinson@fedoraproject.org> - 1.0.23-1
- Update to 1.0.23 - Update to 1.0.23
- Resolves: rhbz#1825941
* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.22-5 * Mon Feb 17 2020 Hans de Goede <hdegoede@redhat.com> - 1.0.22-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild - Add tests-examples subpackage for use by gating tests
- Resolves: rhbz#1681769
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.22-4 * Wed Aug 22 2018 Victor Toso <victortoso@redhat.com> - 1.0.22-1
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Wed Mar 13 2019 Hans de Goede <hdegoede@redhat.com> - 1.0.22-3
- Add tests and examples to a new tests-examples subpackage, so that these
can be used for the upcoming gating stuff
- Add %%check using some of the tests/examples
* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.22-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Tue Aug 07 2018 Victor Toso <victortoso@redhat.com> - 1.0.22-1
- Update to 1.0.22 - Update to 1.0.22
- Resolves: rhbz#1620092
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.21-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Wed Feb 07 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.21-6 * Wed Feb 07 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.21-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild