Skip to contentSkip to conversation

USB port NULL pointer causes segv

Qemu-devel Erik Rull 2 participants 2 messages Aug 17, 2011

lore
Share & tools
lore

Erik Rull

author
#0 lore raw

Hi all,

in usb-linux.c my qemu crashes in
static int usb_host_open(USBHostDevice *dev, int bus_num, int addr, char *port, const char *prod_name, int speed)

because port is NULL.

The line that causes the problem is:
strcpy(dev->port, port);

All Ports are displayed in the qemu monitor info as (null)

when changing the line to:

    if (port)
      strcpy(dev->port, port);
    else
      dev->port[0] = '\0';

everything is fine :-)

Please check this issue and let me know if my workaround is okay.

Best regards,

Erik

#1 lore raw

Hi,

Quoted 5 lines

in usb-linux.c my qemu crashes in
static int usb_host_open(USBHostDevice *dev, int bus_num, int addr, char *port, const char *prod_name, int speed)

because port is NULL.

The attached patches should fix this.

cheers,
Gerd

Quoted 1 line

From 15fd107f500f8a0f6ffa05fa3a9775d37afda1bd Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Wed, 17 Aug 2011 23:35:45 +0200
Subject: [PATCH 1/2] usb-linux: constify port

---
 usb-linux.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
usb-linux.c +8 -5
index 5562187..dec3bc9 100644
@@ -53,7 +53,7 @@ struct usb_ctrltransfer {
     void *data;
 };
 
-typedef int USBScanFunc(void *opaque, int bus_num, int addr, char *port,
+typedef int USBScanFunc(void *opaque, int bus_num, int addr, const char *port,
                         int class_id, int vendor_id, int product_id,
                         const char *product_name, int speed);
 
@@ -1135,7 +1135,8 @@ static int usb_linux_full_speed_compat(USBHostDevice *dev)
 }
 
 static int usb_host_open(USBHostDevice *dev, int bus_num,
-                        int addr, char *port, const char *prod_name, int speed)
+                         int addr, const char *port,
+                         const char *prod_name, int speed)
 {
     int fd = -1, ret;
     char buf[1024];
@@ -1713,7 +1714,8 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
 
 static QEMUTimer *usb_auto_timer;
 
-static int usb_host_auto_scan(void *opaque, int bus_num, int addr, char *port,
+static int usb_host_auto_scan(void *opaque, int bus_num,
+                              int addr, const char *port,
                               int class_id, int vendor_id, int product_id,
                               const char *product_name, int speed)
 {
@@ -1875,7 +1877,8 @@ static const char *usb_class_str(uint8_t class)
     return p->class_name;
 }
 
-static void usb_info_device(Monitor *mon, int bus_num, int addr, char *port,
+static void usb_info_device(Monitor *mon, int bus_num,
+                            int addr, const char *port,
                             int class_id, int vendor_id, int product_id,
                             const char *product_name,
                             int speed)
@@ -1916,7 +1919,7 @@ static void usb_info_device(Monitor *mon, int bus_num, int addr, char *port,
 }
 
 static int usb_host_info_device(void *opaque, int bus_num, int addr,
-                                char *path, int class_id,
+                                const char *path, int class_id,
                                 int vendor_id, int product_id,
                                 const char *product_name,
                                 int speed)
Signature · 1 line
1.7.1
Quoted 1 line

From 3da0c8ed9d83928bbb88c2ffbd3ae8d2eed2e41a Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Wed, 17 Aug 2011 23:36:46 +0200
Subject: [PATCH 2/2] usb-linux: set port to non-NULL for /proc/bus/usb/devices scan

---
 usb-linux.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
usb-linux.c +1 -1
index dec3bc9..f8a47da 100644
@@ -1505,7 +1505,7 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc *func)
     }
     if (device_count && (vendor_id || product_id)) {
         /* Add the last device.  */
-        ret = func(opaque, bus_num, addr, 0, class_id, vendor_id,
+        ret = func(opaque, bus_num, addr, "?", class_id, vendor_id,
                    product_id, product_name, speed);
     }
  the_end:
Signature · 1 line
1.7.1