From 466ab62f106c0f469c1c6e36ddf825cf7c67d899 Mon Sep 17 00:00:00 2001 From: Jan Friesse Date: Wed, 2 May 2018 15:16:03 +0200 Subject: [PATCH] unix-socket: Fix snprintf warning Base N on sizeof sun_path instead of strlen of input path. Signed-off-by: Jan Friesse --- qdevices/unix-socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qdevices/unix-socket.c b/qdevices/unix-socket.c index 464eae7..e344561 100644 --- a/qdevices/unix-socket.c +++ b/qdevices/unix-socket.c @@ -60,7 +60,7 @@ unix_socket_server_create(const char *path, int non_blocking, int backlog) memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; - strncpy(sun.sun_path, path, strlen(path)); + strncpy(sun.sun_path, path, sizeof(sun.sun_path) - 1); unlink(path); if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) != 0) { close(s); @@ -103,7 +103,7 @@ unix_socket_client_create(const char *path, int non_blocking) memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; - strncpy(sun.sun_path, path, strlen(path)); + strncpy(sun.sun_path, path, sizeof(sun.sun_path) - 1); if (non_blocking) { if (utils_fd_set_non_blocking(s) != 0) {