iolog: Ensure that sockaddr_un.sun_path is '\0'-terminated
authorBart Van Assche <bvanassche@acm.org>
Sun, 26 Aug 2018 15:38:28 +0000 (08:38 -0700)
committerBart Van Assche <bvanassche@acm.org>
Fri, 7 Sep 2018 14:21:10 +0000 (07:21 -0700)
This patch fixes Coverity ID 183494.

Fixes: 2f8f4821ef61 ("iolog: allow to read_iolog from unix socket")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
iolog.c

diff --git a/iolog.c b/iolog.c
index f3eedb56252c9b177c2f75d2d50e9a99a2b59696..26c3458638adf94f41d407c5444187e64f299647 100644 (file)
--- 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;
        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
        if (connect(fd, (const struct sockaddr *)&addr, strlen(path) + sizeof(addr.sun_family)) == 0)
                return fd;
        else