WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

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

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] pci/guestdev, iomul: use strlcpy()
From: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
Date: Thu, 4 Jun 2009 15:10:45 +0900
Cc: shimada-yxb@xxxxxxxxxxxxxxx
Delivery-date: Wed, 03 Jun 2009 23:11:09 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.6i
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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] pci/guestdev, iomul: use strlcpy(), Isaku Yamahata <=