[ovs-dev] [PATCH 2/3] datapath: Always null-terminate network device name in create_dp().

Ben Pfaff blp at nicira.com
Tue Apr 27 17:45:57 UTC 2010


strncpy() does not null-terminate its output buffer if the source string's
length is at least as large as its 'count' argument.  We know that the
source and destination buffers are the same size and that the source buffer
is null-terminated, so just use strcpy().

This fixes a kernel BUG message that often occurred when strlen(devname)
was exactly IFNAMSIZ-1.  In such a case, if
internal_dev_port.devname[IFNAMSIZ-1] happened to be nonzero, it would
eventually fail the following check in alloc_netdev_mq():
	BUG_ON(strlen(name) >= sizeof(dev->name));

Bug #2722.
---
 datapath/datapath.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/datapath/datapath.c b/datapath/datapath.c
index be16044..e9590f7 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -246,7 +246,8 @@ static int create_dp(int dp_idx, const char __user *devnamep)
 		goto err_free_dp;
 
 	/* Set up our datapath device. */
-	strncpy(internal_dev_port.devname, devname, IFNAMSIZ - 1);
+	BUILD_BUG_ON(sizeof(internal_dev_port.devname) != sizeof(devname));
+	strcpy(internal_dev_port.devname, devname);
 	internal_dev_port.flags = ODP_PORT_INTERNAL;
 	err = new_dp_port(dp, &internal_dev_port, ODPP_LOCAL);
 	if (err) {
-- 
1.6.6.1





More information about the dev mailing list