aboutsummaryrefslogtreecommitdiff
path: root/lib/socket-util.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-02-22 10:58:36 -0800
committerBen Pfaff <blp@nicira.com>2011-02-22 16:33:58 -0800
commit71d7c22f54ae32d15133571e09ddf7ab435e8afa (patch)
treecfdb28ddeebded6fe6400eb2dd6747a4d769aa45 /lib/socket-util.c
parente868fb3d322f5c46385f1fc6db5bb1ab33f90305 (diff)
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.
Diffstat (limited to 'lib/socket-util.c')
-rw-r--r--lib/socket-util.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 275bf309..e0f34e71 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -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);
}