[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [linux-2.6.18-xen] drivers/xen/: use strlcpy() instead of strncpy()
# HG changeset patch # User Jan Beulich <jbeulich@xxxxxxxx> # Date 1327491109 -3600 # Node ID 06cf8b206bb42584fad133237182ee3519d31649 # Parent 684281d7a1a3f2001047b59700408048b66da178 drivers/xen/: use strlcpy() instead of strncpy() ... for being the safer alternative. In blktap2, snprintf() also gets replaced by strlcpy(), and the bounds check in blktap_sysfs_set_name() also gets adjusted. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> --- diff -r 684281d7a1a3 -r 06cf8b206bb4 drivers/xen/blktap/xenbus.c --- a/drivers/xen/blktap/xenbus.c Wed Jan 25 12:30:46 2012 +0100 +++ b/drivers/xen/blktap/xenbus.c Wed Jan 25 12:31:49 2012 +0100 @@ -72,24 +72,22 @@ return i; len--; } - return (len == 0) ? i : -ERANGE; + return -ERANGE; } static long get_id(const char *str) { - int len,end; + int len; const char *ptr; - char *tptr, num[10]; + char num[10]; len = strsep_len(str, '/', 2); - end = strlen(str); - if ( (len < 0) || (end < 0) ) return -1; + if (len < 0) + return -1; ptr = str + len + 1; - strncpy(num,ptr,end - len); - tptr = num + (end - (len + 1)); - *tptr = '\0'; - DPRINTK("Get_id called for %s (%s)\n",str,num); + strlcpy(num, ptr, ARRAY_SIZE(num)); + DPRINTK("get_id(%s) -> %s\n", str, num); return simple_strtol(num, NULL, 10); } diff -r 684281d7a1a3 -r 06cf8b206bb4 drivers/xen/blktap2/sysfs.c --- a/drivers/xen/blktap2/sysfs.c Wed Jan 25 12:30:46 2012 +0100 +++ b/drivers/xen/blktap2/sysfs.c Wed Jan 25 12:31:49 2012 +0100 @@ -65,12 +65,12 @@ goto out; } - if (strnlen(buf, BLKTAP2_MAX_MESSAGE_LEN) >= BLKTAP2_MAX_MESSAGE_LEN) { + if (strnlen(buf, size) >= size) { err = -EINVAL; goto out; } - snprintf(tap->params.name, sizeof(tap->params.name) - 1, "%s", buf); + strlcpy(tap->params.name, buf, size); err = size; out: diff -r 684281d7a1a3 -r 06cf8b206bb4 drivers/xen/usbback/usbstub.c --- a/drivers/xen/usbback/usbstub.c Wed Jan 25 12:30:46 2012 +0100 +++ b/drivers/xen/usbback/usbstub.c Wed Jan 25 12:31:49 2012 +0100 @@ -110,7 +110,7 @@ portid->handle = handle; portid->portnum = portnum; - strncpy(portid->phys_bus, busid, BUS_ID_SIZE); + strlcpy(portid->phys_bus, busid, BUS_ID_SIZE); spin_lock_irqsave(&port_list_lock, flags); list_add(&portid->id_list, &port_list); diff -r 684281d7a1a3 -r 06cf8b206bb4 drivers/xen/xenoprof/xenoprofile.c --- a/drivers/xen/xenoprof/xenoprofile.c Wed Jan 25 12:30:46 2012 +0100 +++ b/drivers/xen/xenoprof/xenoprofile.c Wed Jan 25 12:31:49 2012 +0100 @@ -553,9 +553,8 @@ xenoprof_arch_init_counter(&init); xenoprof_is_primary = init.is_primary; - /* cpu_type is detected by Xen */ - cpu_type[XENOPROF_CPU_TYPE_SIZE-1] = 0; - strncpy(cpu_type, init.cpu_type, XENOPROF_CPU_TYPE_SIZE - 1); + /* cpu_type is detected by Xen */ + strlcpy(cpu_type, init.cpu_type, XENOPROF_CPU_TYPE_SIZE); xenoprof_ops.cpu_type = cpu_type; init_driverfs(); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |