diff options
| author | 2016-02-17 20:24:43 +0100 | |
|---|---|---|
| committer | 2016-02-17 20:24:43 +0100 | |
| commit | d9bb2d5b11268fe954125c793b7bc3e9caf0ec6a (patch) | |
| tree | a757957aeb753d76211396f5706e03d52d8a7be9 /src | |
| parent | 1a9ff1f75bec47bdc145393f020a0fd60ae0e6da (diff) | |
| download | libirecovery-d9bb2d5b11268fe954125c793b7bc3e9caf0ec6a.tar.gz libirecovery-d9bb2d5b11268fe954125c793b7bc3e9caf0ec6a.tar.bz2 | |
Fix possible invalid free in irecv_open_with_ecid()
irecv_open_with_ecid calls libusb_open() in a loop. When the operation
fails libusb_close() is called with the returned handle - which ideally
should be NULL upon calling libusb_open(). However since we're operating
in a loop this is only the case for the first time libusb_open() is called
and subsequent invocations only overwrite the handle upon success.
Whenever the libusb_open() fails and it is not the first invocation, the
libusb_close() that is called afterwards may cause an invalid free.
To prevent this we set the handle to NULL before calling libusb_open().
Diffstat (limited to 'src')
| -rw-r--r-- | src/libirecovery.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index 9284316..6626b1d 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
| @@ -1116,7 +1116,6 @@ IRECV_API irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, unsigned l | |||
| 1116 | int i = 0; | 1116 | int i = 0; |
| 1117 | struct libusb_device* usb_device = NULL; | 1117 | struct libusb_device* usb_device = NULL; |
| 1118 | struct libusb_device** usb_device_list = NULL; | 1118 | struct libusb_device** usb_device_list = NULL; |
| 1119 | struct libusb_device_handle* usb_handle = NULL; | ||
| 1120 | struct libusb_device_descriptor usb_descriptor; | 1119 | struct libusb_device_descriptor usb_descriptor; |
| 1121 | 1120 | ||
| 1122 | *pclient = NULL; | 1121 | *pclient = NULL; |
| @@ -1150,6 +1149,7 @@ IRECV_API irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, unsigned l | |||
| 1150 | 1149 | ||
| 1151 | debug("opening device %04x:%04x...\n", usb_descriptor.idVendor, usb_descriptor.idProduct); | 1150 | debug("opening device %04x:%04x...\n", usb_descriptor.idVendor, usb_descriptor.idProduct); |
| 1152 | 1151 | ||
| 1152 | struct libusb_device_handle* usb_handle = NULL; | ||
| 1153 | int libusb_error = libusb_open(usb_device, &usb_handle); | 1153 | int libusb_error = libusb_open(usb_device, &usb_handle); |
| 1154 | if (usb_handle == NULL || libusb_error != 0) { | 1154 | if (usb_handle == NULL || libusb_error != 0) { |
| 1155 | debug("%s: can't connect to device: %s\n", __func__, libusb_error_name(libusb_error)); | 1155 | debug("%s: can't connect to device: %s\n", __func__, libusb_error_name(libusb_error)); |
