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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-02-05 23:01:24 +01:00
1 parent 994b589377
commit bd58345b8c
1 file changed
+3 -2
+3 -2
View File
@@ -15,7 +15,7 @@ struct context {
static void pidfile_callback(void *UNUSED(arg), int fd, int UNUSED(events)) 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]; static char cond[MAX_ARG_LEN];
struct inotify_event *ev; struct inotify_event *ev;
@@ -23,11 +23,12 @@ static void pidfile_callback(void *UNUSED(arg), int fd, int UNUSED(events))
char *basename; char *basename;
svc_t *svc; svc_t *svc;
sz = read(fd, ev_buf, sizeof(ev_buf)); sz = read(fd, ev_buf, sizeof(ev_buf) - 1);
if (sz <= 0) { if (sz <= 0) {
_pe("invalid inotify event\n"); _pe("invalid inotify event\n");
return; return;
} }
ev_buf[sz] = 0;
for (ev = (void *)ev_buf; sz > (ssize_t)sizeof(*ev); for (ev = (void *)ev_buf; sz > (ssize_t)sizeof(*ev);
len = sizeof(*ev) + ev->len, ev = (void *)ev + len, sz -= len) { len = sizeof(*ev) + ev->len, ev = (void *)ev + len, sz -= len) {