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