All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] change auto filter output format of "info usbhost" (v2)
@ 2008-09-17 16:50 Andreas Winkelbauer
  0 siblings, 0 replies; only message in thread
From: Andreas Winkelbauer @ 2008-09-17 16:50 UTC (permalink / raw)
  To: aliguori; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 603 bytes --]

This patch changes the output format of the monitor command "info
usbhost" for usb auto filters in usb_host_info().

The VID and PID are now printed as 4 digit hexadecimal numbers with
leading zeros (which is much more usual compared to the current output
format which does not print leading zeros).

In addition to the version 1 of this patch, this version introduces more
changes in the static functions dec2str() and hex2str() (which are only
used by usb_host_info()) to ensure that there won't be any buffer overflows.

Signed-off-by: Andreas Winkelbauer <andreas.winkelbauer@gmx.at>
---

bye,
Andi

[-- Attachment #2: qemu-autofilter-monitor-v2.patch --]
[-- Type: text/x-patch, Size: 1544 bytes --]

diff -uNrp trunk.orig/usb-linux.c trunk/usb-linux.c
--- trunk.orig/usb-linux.c	2008-09-17 02:11:53.000000000 +0200
+++ trunk/usb-linux.c	2008-09-17 14:18:10.000000000 +0200
@@ -1449,20 +1449,20 @@ static int usb_host_info_device(void *op
     return 0;
 }
 
-static void dec2str(int val, char *str)
+static void dec2str(int val, char *str, size_t len)
 {
     if (val == -1)
-        strcpy(str, "*");
+        strncpy(str, "*", len);
     else
-        sprintf(str, "%d", val); 
+        snprintf(str, len, "%d", val); 
 }
 
-static void hex2str(int val, char *str)
+static void hex2str(int val, char *str, size_t len)
 {
     if (val == -1)
-        strcpy(str, "*");
+        strncpy(str, "*", len);
     else
-        sprintf(str, "%x", val);
+        snprintf(str, len, "%04x", val);
 }
 
 void usb_host_info(void)
@@ -1474,12 +1474,12 @@ void usb_host_info(void)
     if (usb_auto_filter)
         term_printf("  Auto filters:\n");
     for (f = usb_auto_filter; f; f = f->next) {
-        char bus[10], addr[10], vid[10], pid[10];
-        dec2str(f->bus_num, bus);
-        dec2str(f->addr, addr);
-        hex2str(f->vendor_id, vid);
-        hex2str(f->product_id, pid);
-    	term_printf("    Device %s.%s ID %s:%s\n", bus, addr, vid, pid);
+        char bus[10], addr[10], vid[5], pid[5];
+        dec2str(f->bus_num, bus, 10);
+        dec2str(f->addr, addr, 10);
+        hex2str(f->vendor_id, vid, 5);
+        hex2str(f->product_id, pid, 5);
+        term_printf("    Device %s.%s ID %s:%s\n", bus, addr, vid, pid);
     }
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-09-17 16:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-17 16:50 [Qemu-devel] [PATCH] change auto filter output format of "info usbhost" (v2) Andreas Winkelbauer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.