From 30b42c0c644c4eb4a969f50cb7a7c97e73595672 Mon Sep 17 00:00:00 2001 From: rpm-build Date: Dec 09 2020 20:45:00 +0000 Subject: 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. patch_name: 1000-Downstream-fix-covscan-issue-close-fd-called-twice.patch present_in_specfile: true location_in_specfile: 11 squash_commits: true --- 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; }