Commit ac4ffb5a130d1304931999781b229e926babeae6
1 parent
ad02ad6f
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> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5290 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
10 additions
and
10 deletions
usb-linux.c
... | ... | @@ -1449,20 +1449,20 @@ static int usb_host_info_device(void *opaque, int bus_num, int addr, |
1449 | 1449 | return 0; |
1450 | 1450 | } |
1451 | 1451 | |
1452 | -static void dec2str(int val, char *str) | |
1452 | +static void dec2str(int val, char *str, size_t size) | |
1453 | 1453 | { |
1454 | 1454 | if (val == -1) |
1455 | - strcpy(str, "*"); | |
1455 | + snprintf(str, size, "*"); | |
1456 | 1456 | else |
1457 | - sprintf(str, "%d", val); | |
1457 | + snprintf(str, size, "%d", val); | |
1458 | 1458 | } |
1459 | 1459 | |
1460 | -static void hex2str(int val, char *str) | |
1460 | +static void hex2str(int val, char *str, size_t size) | |
1461 | 1461 | { |
1462 | 1462 | if (val == -1) |
1463 | - strcpy(str, "*"); | |
1463 | + snprintf(str, size, "*"); | |
1464 | 1464 | else |
1465 | - sprintf(str, "%x", val); | |
1465 | + snprintf(str, size, "%x", val); | |
1466 | 1466 | } |
1467 | 1467 | |
1468 | 1468 | void usb_host_info(void) |
... | ... | @@ -1475,10 +1475,10 @@ void usb_host_info(void) |
1475 | 1475 | term_printf(" Auto filters:\n"); |
1476 | 1476 | for (f = usb_auto_filter; f; f = f->next) { |
1477 | 1477 | char bus[10], addr[10], vid[10], pid[10]; |
1478 | - dec2str(f->bus_num, bus); | |
1479 | - dec2str(f->addr, addr); | |
1480 | - hex2str(f->vendor_id, vid); | |
1481 | - hex2str(f->product_id, pid); | |
1478 | + dec2str(f->bus_num, bus, sizeof(bus)); | |
1479 | + dec2str(f->addr, addr, sizeof(addr)); | |
1480 | + hex2str(f->vendor_id, vid, sizeof(vid)); | |
1481 | + hex2str(f->product_id, pid, sizeof(pid)); | |
1482 | 1482 | term_printf(" Device %s.%s ID %s:%s\n", bus, addr, vid, pid); |
1483 | 1483 | } |
1484 | 1484 | } | ... | ... |