From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [5290] Don't use sprintf() or strcpy()
Date: Mon, 22 Sep 2008 15:04:31 +0000 [thread overview]
Message-ID: <E1Khmxj-0004in-Rn@cvs.savannah.gnu.org> (raw)
Revision: 5290
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5290
Author: aliguori
Date: 2008-09-22 15:04:31 +0000 (Mon, 22 Sep 2008)
Log Message:
-----------
Don't use sprintf() or strcpy()
They are unsafe. The current code is correct, but to be safer, we should pass
an explicit size.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Modified Paths:
--------------
trunk/usb-linux.c
Modified: trunk/usb-linux.c
===================================================================
--- trunk/usb-linux.c 2008-09-22 14:49:01 UTC (rev 5289)
+++ trunk/usb-linux.c 2008-09-22 15:04:31 UTC (rev 5290)
@@ -1449,20 +1449,20 @@
return 0;
}
-static void dec2str(int val, char *str)
+static void dec2str(int val, char *str, size_t size)
{
if (val == -1)
- strcpy(str, "*");
+ snprintf(str, size, "*");
else
- sprintf(str, "%d", val);
+ snprintf(str, size, "%d", val);
}
-static void hex2str(int val, char *str)
+static void hex2str(int val, char *str, size_t size)
{
if (val == -1)
- strcpy(str, "*");
+ snprintf(str, size, "*");
else
- sprintf(str, "%x", val);
+ snprintf(str, size, "%x", val);
}
void usb_host_info(void)
@@ -1475,10 +1475,10 @@
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);
+ dec2str(f->bus_num, bus, sizeof(bus));
+ dec2str(f->addr, addr, sizeof(addr));
+ hex2str(f->vendor_id, vid, sizeof(vid));
+ hex2str(f->product_id, pid, sizeof(pid));
term_printf(" Device %s.%s ID %s:%s\n", bus, addr, vid, pid);
}
}
reply other threads:[~2008-09-22 15:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1Khmxj-0004in-Rn@cvs.savannah.gnu.org \
--to=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.