statd: null terminate recv() buffer from netlink

Fixes CID 331053

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-11-20 13:34:19 +01:00
parent a4d02630c9
commit 2191202f2a
+4 -1
View File
@@ -343,7 +343,7 @@ static void nl_event_cb(struct ev_loop *, struct ev_io *w, int)
int err;
int len;
len = recv(statd->nl.sd, buf, sizeof(buf), 0);
len = recv(statd->nl.sd, buf, sizeof(buf) - 1, 0);
if (len < 0) {
ERROR("Error, netlink recv failed: %s", strerror(errno));
close(statd->nl.sd);
@@ -354,6 +354,9 @@ static void nl_event_cb(struct ev_loop *, struct ev_io *w, int)
exit(EXIT_FAILURE);
}
/* nl_process_msg() expects NULL terminated buffer */
buf[len] = 0;
for (nlh = (struct nlmsghdr *)buf; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len)) {
err = nl_process_msg(nlh, statd);
if (err)