2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

util: Don't read over 'size - 1' bytes of source string in ovs_strlcpy().

The blind replacement of strncpy() by ovs_strlcpy() is risky because
strncpy() never reads more bytes from its source string than necessary to
write its destination string, but ovs_strlcpy() and the OpenBSD function
that inspired it both read the entire source string.  This avoids that
problem.

Given that change, we can use ovs_strlcpy() in a few more places, and
this commit does that too.

Coverity #10697,10696,10695,10694,10693,10692,10691,10690.
This commit is contained in:
Ben Pfaff
2011-02-22 10:41:15 -08:00
parent 0e191d8fae
commit e868fb3d32
3 changed files with 8 additions and 9 deletions

View File

@@ -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,8 +445,7 @@ name_table_reset(void)
nn = xzalloc(sizeof *nn);
nn->ifi_index = change.ifi_index;
strncpy(nn->ifname, change.ifname, IFNAMSIZ);
nn->ifname[IFNAMSIZ - 1] = '\0';
ovs_strlcpy(nn->ifname, change.ifname, IFNAMSIZ);
hmap_insert(&name_map, &nn->node, hash_int(nn->ifi_index, 0));
}
}