[ovs-dev] [coverity 11/14] lib: Replace remaining unsafe strncpy()s with ovs_strlcpy().
Justin Pettit
jpettit at nicira.com
Tue Feb 22 01:44:54 UTC 2011
---
lib/ofp-print.c | 2 +-
lib/route-table.c | 4 ++--
lib/socket-util.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 0e2cb0f..b9621a4 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -1315,7 +1315,7 @@ ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
for (; n--; ts++) {
char name[OFP_MAX_TABLE_NAME_LEN + 1];
- strncpy(name, ts->name, sizeof name);
+ ovs_strlcpy(name, ts->name, sizeof name);
name[OFP_MAX_TABLE_NAME_LEN] = '\0';
ds_put_format(string, " %d: %-8s: ", ts->table_id, name);
diff --git a/lib/route-table.c b/lib/route-table.c
index 64a5c1e..77a53d5 100644
--- a/lib/route-table.c
+++ b/lib/route-table.c
@@ -111,7 +111,7 @@ route_table_get_name(ovs_be32 ip, char name[IFNAMSIZ])
nn = name_node_lookup(ifindex);
if (nn) {
- strncpy(name, nn->ifname, IFNAMSIZ);
+ ovs_strlcpy(name, nn->ifname, IFNAMSIZ);
return true;
}
}
@@ -445,7 +445,7 @@ name_table_reset(void)
nn = xzalloc(sizeof *nn);
nn->ifi_index = change.ifi_index;
- strncpy(nn->ifname, change.ifname, IFNAMSIZ);
+ ovs_strlcpy(nn->ifname, change.ifname, IFNAMSIZ);
nn->ifname[IFNAMSIZ - 1] = '\0';
hmap_insert(&name_map, &nn->node, hash_int(nn->ifi_index, 0));
}
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 275bf30..08a277a 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -233,7 +233,7 @@ static void
make_sockaddr_un__(const char *name, struct sockaddr_un *un, socklen_t *un_len)
{
un->sun_family = AF_UNIX;
- strncpy(un->sun_path, name, sizeof un->sun_path);
+ ovs_strlcpy(un->sun_path, name, sizeof un->sun_path);
un->sun_path[sizeof un->sun_path - 1] = '\0';
*un_len = (offsetof(struct sockaddr_un, sun_path)
+ strlen (un->sun_path) + 1);
--
1.7.1
More information about the dev
mailing list