From bd58345b8ca6acd553b4b8b06bcdb4a91cd789f7 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 5 Feb 2016 23:01:24 +0100 Subject: [PATCH] Fix Coverity warning for unterminated string from read() The read() does not zero terminate the string, then we call strstr() on that string ... Signed-off-by: Joachim Nilsson --- plugins/pidfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index a0d8da5a..0e63fcd8 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -15,7 +15,7 @@ struct context { static void pidfile_callback(void *UNUSED(arg), int fd, int UNUSED(events)) { - static char ev_buf[8 *(sizeof(struct inotify_event) + NAME_MAX + 1)]; + static char ev_buf[8 *(sizeof(struct inotify_event) + NAME_MAX + 1) + 1]; static char cond[MAX_ARG_LEN]; struct inotify_event *ev; @@ -23,11 +23,12 @@ static void pidfile_callback(void *UNUSED(arg), int fd, int UNUSED(events)) char *basename; svc_t *svc; - sz = read(fd, ev_buf, sizeof(ev_buf)); + sz = read(fd, ev_buf, sizeof(ev_buf) - 1); if (sz <= 0) { _pe("invalid inotify event\n"); return; } + ev_buf[sz] = 0; for (ev = (void *)ev_buf; sz > (ssize_t)sizeof(*ev); len = sizeof(*ev) + ev->len, ev = (void *)ev + len, sz -= len) {