From c7d23f4bd20fcb255619508210ed91f185f0ff6f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 26 Aug 2018 08:38:28 -0700 Subject: [PATCH] iolog: Ensure that sockaddr_un.sun_path is '\0'-terminated This patch fixes Coverity ID 183494. Fixes: 2f8f4821ef61 ("iolog: allow to read_iolog from unix socket") Signed-off-by: Bart Van Assche --- iolog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iolog.c b/iolog.c index f3eedb56..26c34586 100644 --- a/iolog.c +++ b/iolog.c @@ -580,7 +580,10 @@ static int open_socket(const char *path) if (fd < 0) return fd; addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path, sizeof(addr.sun_path)); + if (snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path) >= + sizeof(addr.sun_path)) + log_err("%s: path name %s is too long for a Unix socket\n", + __func__, path); if (connect(fd, (const struct sockaddr *)&addr, strlen(path) + sizeof(addr.sun_family)) == 0) return fd; else -- 2.25.1