From 314f4ff998f6ba63607ce3be6cd7193a39cd1f78 Mon Sep 17 00:00:00 2001 From: Bei Zhang Date: Fri, 23 Aug 2013 01:10:35 -0700 Subject: [PATCH] Darwin: Fix a SIGFPE * GetPipeProperties() may fail when the device is unplugged if DeviceVersion is not greater than 320. * In this case maxPacketSize will be zero and the integer division will throw a EXC_ARITHMETIC signal. * Closes #136 --- libusb/os/darwin_usb.c | 10 ++++++++-- libusb/version_nano.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 0105e3c..146218b 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -1445,8 +1445,14 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) { cInterface = &priv->interfaces[iface]; - (*(cInterface->interface))->GetPipeProperties (cInterface->interface, pipeRef, &direction, &number, - &transferType, &maxPacketSize, &interval); + ret = (*(cInterface->interface))->GetPipeProperties (cInterface->interface, pipeRef, &direction, &number, + &transferType, &maxPacketSize, &interval); + + if (ret) { + usbi_err (TRANSFER_CTX (transfer), "bulk transfer failed (dir = %s): %s (code = 0x%08x)", IS_XFERIN(transfer) ? "In" : "Out", + darwin_error_str(ret), ret); + return darwin_to_libusb (ret); + } if (0 != (transfer->length % maxPacketSize)) { /* do not need a zero packet */ diff --git a/libusb/version_nano.h b/libusb/version_nano.h index d576271..6d6aaaa 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10858 +#define LIBUSB_NANO 10859 -- 2.7.4