From 61bd9d7d700de2a36b0ab82ac5ac6582ac0b24c4 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Mon, 27 Nov 2017 11:30:16 -0500 Subject: [PATCH] libusb: early return if we fail to get a config descriptor, otherwise the memory returned is invalid (and should not be freed either) --- input/drivers_hid/libusb_hid.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/input/drivers_hid/libusb_hid.c b/input/drivers_hid/libusb_hid.c index 5d681a9947..d0eb1250d7 100644 --- a/input/drivers_hid/libusb_hid.c +++ b/input/drivers_hid/libusb_hid.c @@ -165,7 +165,13 @@ static void libusb_get_description(struct libusb_device *device, unsigned i, k; struct libusb_config_descriptor *config; - libusb_get_config_descriptor(device, 0, &config); + int desc_ret = libusb_get_config_descriptor(device, 0, &config); + + if (desc_ret != 0) + { + RARCH_ERR("Error %d getting libusb config descriptor\n", desc_ret); + return; + } for (i = 0; i < (int)config->bNumInterfaces; i++) { @@ -208,11 +214,12 @@ static void libusb_get_description(struct libusb_device *device, } } } + goto ret; } } - ret: +ret: libusb_free_config_descriptor(config); }