* [Qemu-devel] [PATCH] usb: initialize libusb_device to avoid crash
@ 2014-06-20 6:12 Jincheng Miao
2014-06-20 7:49 ` Gonglei (Arei)
0 siblings, 1 reply; 2+ messages in thread
From: Jincheng Miao @ 2014-06-20 6:12 UTC (permalink / raw)
To: qemu-devel; +Cc: kraxel, Jincheng Miao
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 <jmiao@redhat.com>
---
hw/usb/host-libusb.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 33b5b9f..c189147 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -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;
@@ -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;
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] usb: initialize libusb_device to avoid crash
2014-06-20 6:12 [Qemu-devel] [PATCH] usb: initialize libusb_device to avoid crash Jincheng Miao
@ 2014-06-20 7:49 ` Gonglei (Arei)
0 siblings, 0 replies; 2+ messages in thread
From: Gonglei (Arei) @ 2014-06-20 7:49 UTC (permalink / raw)
To: Jincheng Miao, qemu-devel@nongnu.org; +Cc: kraxel@redhat.com
> -----Original Message-----
> From: qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org
> [mailto:qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org] On
> Behalf Of Jincheng Miao
> Sent: Friday, June 20, 2014 2:13 PM
> To: qemu-devel@nongnu.org
> Cc: kraxel@redhat.com; Jincheng Miao
> Subject: [Qemu-devel] [PATCH] usb: initialize libusb_device to avoid crash
>
> 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 <jmiao@redhat.com>
> ---
> hw/usb/host-libusb.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
Best regards,
-Gonglei
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-20 7:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-20 6:12 [Qemu-devel] [PATCH] usb: initialize libusb_device to avoid crash Jincheng Miao
2014-06-20 7:49 ` Gonglei (Arei)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).