2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

util: New function ovs_strzcpy().

Static analyzers hate strncpy().  This new function shares its property of
initializing an entire buffer, without its nasty habit of failing to
null-terminate long strings.

Coverity #10697,10696,10695,10694,10693,10692,10691,10690.
This commit is contained in:
Ben Pfaff
2011-02-22 10:58:36 -08:00
parent e868fb3d32
commit 71d7c22f54
5 changed files with 35 additions and 12 deletions

View File

@@ -233,8 +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);
un->sun_path[sizeof un->sun_path - 1] = '\0';
ovs_strzcpy(un->sun_path, name, sizeof un->sun_path);
*un_len = (offsetof(struct sockaddr_un, sun_path)
+ strlen (un->sun_path) + 1);
}