Fix a crash after libusb_exit API has been misused

Resolves: #2050638
This commit is contained in:
Benjamin Berg 2022-02-10 12:06:41 +01:00
parent 6719df21e1
commit ac977fad6e
2 changed files with 27 additions and 0 deletions

24
1058.patch Normal file
View File

@ -0,0 +1,24 @@
From 2529a3fc4f987f93e0774af865ac7cb6557bd0c2 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
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))

View File

@ -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.