[PATCH v2 5/5] vhost: use strlcpy instead of strncpy
Stephen Hemminger
stephen at networkplumber.org
Thu Dec 19 23:49:55 CET 2024
Some tools such as gcc address sanitizer will complain if strncpy
is used to completely fill a string since it will not be null
terminated. Since the previous code forced as null at end,
use strlcpy() to get the same effect.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
lib/vhost/socket.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index d29d15494c..f938189cc2 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -359,8 +359,7 @@ create_unix_socket(struct vhost_user_socket *vsocket)
memset(un, 0, sizeof(*un));
un->sun_family = AF_UNIX;
- strncpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
- un->sun_path[sizeof(un->sun_path) - 1] = '\0';
+ strlcpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
vsocket->socket_fd = fd;
return 0;
--
2.45.2
More information about the dev
mailing list