strncpy() has pretty annoying semantics.  One bit that is odd is that
it does not guarantee that the destination string will be null
terminated.  If no terminator is found in the first N bytes of the
source, it just fills the destination buffer and doesn't terminate it.

The changes here are to address cases where the destination could be
left without a terminator by simply using strlcpy() instead.  In
passing, use sizeof() instead of a constant where possible for the
destination buffer length.

Signed-off-by: Russell Bryant <rbry...@redhat.com>
---
 datapath/linux/compat/genetlink-openvswitch.c | 2 +-
 datapath/vport-gre.c                          | 4 ++--
 datapath/vport-lisp.c                         | 2 +-
 datapath/vport-vxlan.c                        | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/datapath/linux/compat/genetlink-openvswitch.c 
b/datapath/linux/compat/genetlink-openvswitch.c
index 08f0fab..b37e4a5 100644
--- a/datapath/linux/compat/genetlink-openvswitch.c
+++ b/datapath/linux/compat/genetlink-openvswitch.c
@@ -28,7 +28,7 @@ int rpl___genl_register_family(struct rpl_genl_family *f)
 
        f->compat_family.id = f->id;
        f->compat_family.hdrsize = f->hdrsize;
-       strncpy(f->compat_family.name, f->name, GENL_NAMSIZ);
+       strlcpy(f->compat_family.name, f->name, sizeof(f->compat_family.name));
        f->compat_family.version = f->version;
        f->compat_family.maxattr = f->maxattr;
        f->compat_family.netnsok = f->netnsok;
diff --git a/datapath/vport-gre.c b/datapath/vport-gre.c
index c0ed009..5566b12 100644
--- a/datapath/vport-gre.c
+++ b/datapath/vport-gre.c
@@ -264,7 +264,7 @@ static struct vport *gre_create(const struct vport_parms 
*parms)
        if (IS_ERR(vport))
                goto error;
 
-       strncpy(vport_priv(vport), parms->name, IFNAMSIZ);
+       strlcpy(vport_priv(vport), parms->name, IFNAMSIZ);
        rcu_assign_pointer(ovs_net->vport_net.gre_vport, vport);
        return vport;
 
@@ -339,7 +339,7 @@ static struct vport *gre64_create(const struct vport_parms 
*parms)
        if (IS_ERR(vport))
                goto error;
 
-       strncpy(vport_priv(vport), parms->name, IFNAMSIZ);
+       strlcpy(vport_priv(vport), parms->name, IFNAMSIZ);
        rcu_assign_pointer(ovs_net->vport_net.gre64_vport, vport);
        return vport;
 error:
diff --git a/datapath/vport-lisp.c b/datapath/vport-lisp.c
index 293002f..8f0301d 100644
--- a/datapath/vport-lisp.c
+++ b/datapath/vport-lisp.c
@@ -364,7 +364,7 @@ static struct vport *lisp_tnl_create(const struct 
vport_parms *parms)
 
        lisp_port = lisp_vport(vport);
        lisp_port->dst_port = htons(dst_port);
-       strncpy(lisp_port->name, parms->name, IFNAMSIZ);
+       strlcpy(lisp_port->name, parms->name, sizeof(lisp_port->name));
 
        err = lisp_socket_init(lisp_port, net);
        if (err)
diff --git a/datapath/vport-vxlan.c b/datapath/vport-vxlan.c
index c25cc58..74ed39d 100644
--- a/datapath/vport-vxlan.c
+++ b/datapath/vport-vxlan.c
@@ -176,7 +176,7 @@ static struct vport *vxlan_tnl_create(const struct 
vport_parms *parms)
                return vport;
 
        vxlan_port = vxlan_vport(vport);
-       strncpy(vxlan_port->name, parms->name, IFNAMSIZ);
+       strlcpy(vxlan_port->name, parms->name, sizeof(vxlan_port->name));
 
        a = nla_find_nested(options, OVS_TUNNEL_ATTR_EXTENSION);
        if (a) {
-- 
2.1.0

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to