Skip to content

Commit

Permalink
usb: initialize libusb_device to avoid crash
Browse files Browse the repository at this point in the history
If libusb_get_device_list() fails, the uninitialized local variable
libusb_device would be passed to libusb_free_device_list(), that
will cause a crash, like:
(gdb) bt
 #0  0x00007fbbb4bafc10 in pthread_mutex_lock () from /lib64/libpthread.so.0
 #1  0x00007fbbb233e653 in libusb_unref_device (dev=0x6275682d627375)
     at core.c:902
 #2  0x00007fbbb233e739 in libusb_free_device_list (list=0x7fbbb6e8436e,
     unref_devices=<optimized out>) at core.c:653
 #3  0x00007fbbb6cd80a4 in usb_host_auto_check (unused=unused@entry=0x0)
     at hw/usb/host-libusb.c:1446
 #4  0x00007fbbb6cd8525 in usb_host_initfn (udev=0x7fbbbd3c5670)
     at hw/usb/host-libusb.c:912
 #5  0x00007fbbb6cc123b in usb_device_init (dev=0x7fbbbd3c5670)
     at hw/usb/bus.c:106
 ...

So initialize libusb_device at the begin time.

Signed-off-by: Jincheng Miao <[email protected]>
Reviewed-by: Gonglei <[email protected]>
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
ryanmiao authored and kraxel committed Jul 1, 2014
1 parent c340a28 commit 3ce2144
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hw/usb/host-libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ static void usb_host_auto_check(void *unused)
{
struct USBHostDevice *s;
struct USBAutoFilter *f;
libusb_device **devs;
libusb_device **devs = NULL;
struct libusb_device_descriptor ddesc;
int unconnected = 0;
int i, n;
Expand Down Expand Up @@ -1623,7 +1623,7 @@ static void usb_host_auto_check(void *unused)

void usb_host_info(Monitor *mon, const QDict *qdict)
{
libusb_device **devs;
libusb_device **devs = NULL;
struct libusb_device_descriptor ddesc;
char port[16];
int i, n;
Expand Down

0 comments on commit 3ce2144

Please sign in to comment.