diff options
author | Peter Stuge <peter@stuge.se> | 2012-04-07 03:55:36 +0200 |
---|---|---|
committer | Pete Batard <pete@akeo.ie> | 2012-04-09 22:29:41 +0100 |
commit | 5b7d1c57f8dea7d6090d7478e4f39075c17decdb (patch) | |
tree | b721f9f437f165463931127d09381f6ced61062c | |
parent | 974251ba94861d03dbe9837a902d84e83d301cda (diff) | |
download | libusb-5b7d1c57f8dea7d6090d7478e4f39075c17decdb.tar.gz |
OpenBSD: Fix warning: 'hpriv' may be used uninitialized
As reported in http://marc.info/?m=133376187514495
The variable would be used uninitialized when the internal list of
open devices is empty as obsd_handle_events() checks which device
the event fd belongs to, which can not actually happen, but if it
ever does happen then we will now return LIBUSB_ERROR_NO_DEVICE.
Reported-by: Xiaofan Chen <xiaofanc@gmail.com>
-rw-r--r-- | libusb/os/openbsd_usb.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libusb/os/openbsd_usb.c b/libusb/os/openbsd_usb.c index d0792b3..9958cfe 100644 --- a/libusb/os/openbsd_usb.c +++ b/libusb/os/openbsd_usb.c @@ -484,7 +484,7 @@ obsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds, int num_ready) { struct libusb_device_handle *handle; - struct handle_priv *hpriv; + struct handle_priv *hpriv = NULL; struct usbi_transfer *itransfer; struct pollfd *pollfd; int i, err = 0; @@ -498,6 +498,7 @@ obsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds, if (!pollfd->revents) continue; + hpriv = NULL; num_ready--; list_for_each_entry(handle, &ctx->open_devs, list, struct libusb_device_handle) { @@ -505,6 +506,14 @@ obsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds, if (hpriv->pipe[0] == pollfd->fd) break; + + hpriv = NULL; + } + + if (NULL == hpriv) { + usbi_dbg("fd %d is not an event pipe!", pollfd->fd); + err = ENOENT; + break; } if (pollfd->revents & POLLERR) { |