[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] pci/guestdev, iomul: use strlcpy()



pci/guestdev, iomul: use strlcpy()

use strlcpy() to make them robust.

Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>

diff --git a/drivers/pci/guestdev.c b/drivers/pci/guestdev.c
--- a/drivers/pci/guestdev.c
+++ b/drivers/pci/guestdev.c
@@ -104,8 +104,7 @@ static int __init pci_get_hid_uid(char *
        if (len <= 0 || HID_LEN < len)
                goto format_err_end;
 
-       strncpy(hid, sp, len);
-       hid[len] = '\0';
+       strlcpy(hid, sp, len);
 
        if (*ep == '-') { /* no uid */
                uid[0] = '\0';
@@ -122,8 +121,7 @@ static int __init pci_get_hid_uid(char *
        if (len <= 0 || UID_LEN < len)
                goto format_err_end;
 
-       strncpy(uid, sp, len);
-       uid[len] = '\0';
+       strlcpy(uid, sp, len);
        return TRUE;
 
 format_err_end:
@@ -549,7 +547,7 @@ static int __init pci_guestdev_setup(cha
 {
        if (strlen(str) >= COMMAND_LINE_SIZE)
                return 0;
-       strcpy(guestdev_param, str);
+       strlcpy(guestdev_param, str, sizeof(guestdev_param));
        return 1;
 }
 
diff --git a/drivers/pci/iomulti.c b/drivers/pci/iomulti.c
--- a/drivers/pci/iomulti.c
+++ b/drivers/pci/iomulti.c
@@ -412,8 +412,7 @@ static int pci_is_iomul_dev_param(struct
                        uint8_t bus;
                        uint8_t dev;
 
-                       strncpy(tmp, p, len);
-                       *(tmp + len) = '\0';
+                       strlcpy(tmp, p, len);
                        if (pci_get_sbd(tmp, &seg, &bus, &dev) == 0 &&
                            pci_domain_nr(pdev->bus) == seg &&
                            pdev->bus->number == bus &&
@@ -437,7 +436,7 @@ static int __init pci_iomul_param_setup(
                return 0;
 
        /* parse it after pci bus scanning */
-       strncpy(iomul_param, str, sizeof(iomul_param));
+       strlcpy(iomul_param, str, sizeof(iomul_param));
        return 1;
 }
 __setup("guestiomuldev=", pci_iomul_param_setup);
diff --git a/drivers/pci/reserve.c b/drivers/pci/reserve.c
--- a/drivers/pci/reserve.c
+++ b/drivers/pci/reserve.c
@@ -135,9 +135,9 @@ unsigned long pci_reserve_size_mem(struc
 
 static int __init pci_reserve_setup(char *str)
 {
-       if (strlen(str) > sizeof(pci_reserve_param))
+       if (strlen(str) >= sizeof(pci_reserve_param))
                return 0;
-       strcpy(pci_reserve_param, str);
+       strlcpy(pci_reserve_param, str, sizeof(pci_reserve_param));
        return 1;
 }
 __setup("pci_reserve=", pci_reserve_setup);


-- 
yamahata

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.