diff options
author | Sean McBride <sean@rogue-research.com> | 2024-01-06 01:46:12 -0500 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2024-01-19 18:18:05 +0100 |
commit | a91657aba0bdea53bc21002b9f21d33fc1bea99a (patch) | |
tree | 598d41a57845e7cd7b382f7fe5c83cbe6cf35542 | |
parent | 9401e6c7d9b45234f14075ccfcaaeccc48fadbe4 (diff) | |
download | libusb-a91657aba0bdea53bc21002b9f21d33fc1bea99a.tar.gz |
darwin: Avoid error checking regression
Commit 13a69533 slightly/subtly made an incorrect change to error
checking. Before that commit, we had
if (kIOReturnSuccess != kresult || !plugInInterface) {
return NULL;
}
which was correct. The commit changed the function signature. Instead of
returning the pointer directly, it now returns an error code directly,
and the pointer by reference. The above block became:
if (kIOReturnSuccess != kresult || !plugInInterface) {
return darwin_to_libusb(kresult);
}
But if kresult is somehow kIOReturnSuccess but plugInInterface is NULL
(probably impossible), then we'd return LIBUSB_SUCCESS but a NULL
pointer, which is a nonsense combination.
Closes #1430
-rw-r--r-- | libusb/os/darwin_usb.c | 12 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 11 insertions, 3 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 04e6d31..607d8da 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -573,10 +573,14 @@ static int darwin_device_from_service (struct libusb_context *ctx, io_service_t nanosleep(&(struct timespec){.tv_sec = 0, .tv_nsec = 1000}, NULL); } - if (kIOReturnSuccess != kresult || !plugInInterface) { + if (kIOReturnSuccess != kresult) { usbi_dbg (ctx, "could not set up plugin for service: %s", darwin_error_str (kresult)); return darwin_to_libusb(kresult); } + if (!plugInInterface) { + usbi_dbg (ctx, "could not set up plugin for service"); + return LIBUSB_ERROR_OTHER; + } (void)(*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(get_device_interface_id()), (LPVOID)device); @@ -1792,10 +1796,14 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, uint8 /* We no longer need the intermediate plug-in */ /* Use release instead of IODestroyPlugInInterface to avoid stopping IOServices associated with this device */ (*plugInInterface)->Release (plugInInterface); - if (kresult != kIOReturnSuccess || !IOINTERFACE(cInterface)) { + if (kresult != kIOReturnSuccess) { usbi_err (ctx, "QueryInterface: %s", darwin_error_str(kresult)); return darwin_to_libusb (kresult); } + if (!IOINTERFACE(cInterface)) { + usbi_err (ctx, "QueryInterface: returned null interface"); + return LIBUSB_ERROR_OTHER; + } /* claim the interface */ kresult = (*IOINTERFACE(cInterface))->USBInterfaceOpen(IOINTERFACE(cInterface)); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 1e3ac71..2ed5ff2 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11858 +#define LIBUSB_NANO 11859 |