Core: correctly check usbi_read() returned value
authorChris Dickens <christopher.a.dickens@gmail.com>
Fri, 2 Aug 2013 09:33:41 +0000 (11:33 +0200)
committerLudovic Rousseau <ludovic.rousseau+github@gmail.com>
Fri, 2 Aug 2013 09:37:21 +0000 (11:37 +0200)
For messages received on the hotplug pipe, the message was read via
usbi_read() (ssize_t) and compared against the size of the message
struct (size_t). usbi_read() returns -1 on an error condition, so some
systems can cast the ssize_t to size_t for the comparison, making it
equal to SIZE_MAX and causing the error check condition to incorrectly
evaluate to false.

libusb/io.c
libusb/version_nano.h

index 8438e77..64712c2 100644 (file)
@@ -1999,8 +1999,8 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
 
                /* read the message from the hotplug thread */
                ret = usbi_read(ctx->hotplug_pipe[0], &message, sizeof (message));
-               if (ret < sizeof(message)) {
-                       usbi_err(ctx, "hotplug pipe read error %d < %d",
+               if (ret != sizeof(message)) {
+                       usbi_err(ctx, "hotplug pipe read error %d != %u",
                                 ret, sizeof(message));
                        r = LIBUSB_ERROR_OTHER;
                        goto handled;
index 13fec84..8e5c2d3 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10798
+#define LIBUSB_NANO 10799