OpenBSD: allow opening ugen devices multiple times
authorTheo Buehler <tb@openbsd.org>
Wed, 5 Aug 2020 13:23:45 +0000 (15:23 +0200)
committerChris Dickens <christopher.a.dickens@gmail.com>
Mon, 10 Aug 2020 17:56:29 +0000 (10:56 -0700)
Fix an OpenBSD backend bug where an existing open file descriptor is
overwritten if a libusb user attempts to open the same ugen(4) device
multiple times. This was observed with sane-backends and broke scanning.

Fix from stsp@openbsd.org

Closes #763

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/openbsd_usb.c
libusb/version_nano.h

index f5b0470..acd8c2a 100644 (file)
@@ -225,15 +225,17 @@ obsd_open(struct libusb_device_handle *handle)
        char devnode[16];
 
        if (dpriv->devname) {
+               int fd;
                /*
                 * Only open ugen(4) attached devices read-write, all
                 * read-only operations are done through the bus node.
                 */
                snprintf(devnode, sizeof(devnode), DEVPATH "%s.00",
                    dpriv->devname);
-               dpriv->fd = open(devnode, O_RDWR);
-               if (dpriv->fd < 0)
+               fd = open(devnode, O_RDWR);
+               if (fd < 0)
                        return _errno_to_libusb(errno);
+               dpriv->fd = fd;
 
                usbi_dbg("open %s: fd %d", devnode, dpriv->fd);
        }
index 6d12f78..baa7aa2 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11527
+#define LIBUSB_NANO 11528