From ac977fad6ed5042fb7c563ba8cc4effe5de184fa Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 10 Feb 2022 12:06:41 +0100 Subject: [PATCH] Fix a crash after libusb_exit API has been misused Resolves: #2050638 --- 1058.patch | 24 ++++++++++++++++++++++++ libusb1.spec | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 1058.patch diff --git a/1058.patch b/1058.patch new file mode 100644 index 0000000..d504455 --- /dev/null +++ b/1058.patch @@ -0,0 +1,24 @@ +From 2529a3fc4f987f93e0774af865ac7cb6557bd0c2 Mon Sep 17 00:00:00 2001 +From: Benjamin Berg +Date: Fri, 4 Feb 2022 22:50:28 +0100 +Subject: [PATCH] core: Unset device ctx if it has been destroyed + +Devices can outlive their context in some cases (in particular with +python garbage collection). Guard against this happening by clearing the +ctx pointer so that it is not pointing to uninitialized memory. +--- + libusb/core.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libusb/core.c b/libusb/core.c +index 7893ac23..1c1ada14 100644 +--- a/libusb/core.c ++++ b/libusb/core.c +@@ -2441,6 +2441,7 @@ void API_EXPORTED libusb_exit(libusb_context *ctx) + for_each_device(_ctx, dev) { + usbi_warn(_ctx, "device %d.%d still referenced", + dev->bus_number, dev->device_address); ++ DEVICE_CTX(dev) = NULL; + } + + if (!list_empty(&_ctx->open_devs)) diff --git a/libusb1.spec b/libusb1.spec index 8eb7ef5..34310dc 100644 --- a/libusb1.spec +++ b/libusb1.spec @@ -12,6 +12,9 @@ BuildRequires: gcc Provides: libusbx = %{version}-%{release} Obsoletes: libusbx < %{version}-%{release} +# Fix a crash after libusb_exit API has been misused +# https://bugzilla.redhat.com/show_bug.cgi?id=2050638 +Patch0001: https://github.com/libusb/libusb/pull/1058.patch %description This package provides a way for applications to access USB devices.