Commit c40a98c1 authored by Petr Baudis's avatar Petr Baudis
Browse files

compctld recvmsg(): Allocate space for cmsg

parent 0b46e841
......@@ -30,9 +30,10 @@ connectd(void)
};
char cbuf[CMSG_SPACE(sizeof(cred))];
struct msghdr msg = {0};
msg.msg_control = cbuf;
msg.msg_controllen = sizeof(cbuf);
struct msghdr msg = {
.msg_control = cbuf,
.msg_controllen = sizeof(cbuf),
};
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
......
......@@ -121,19 +121,27 @@ main(int argc, char *argv[])
/* Decode the message with credentials. */
struct msghdr msg;
struct ucred *cred;
char cbuf[CMSG_SPACE(sizeof(*cred))];
struct msghdr msg = {
.msg_control = cbuf,
.msg_controllen = sizeof(cbuf),
};
char *errmsg;
if (recvmsg(fd, &msg, MSG_WAITALL) <= 0) {
recvagain:
if (recvmsg(fd, &msg, MSG_WAITALL) < 0) {
if (errno == EAGAIN)
goto recvagain;
errmsg = "recvmsg";
sockerror:
logperror(errmsg);
close(fd);
continue;
}
struct ucred *cred;
struct cmsghdr *cmsg;
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN(sizeof(struct ucred))) {
if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN(sizeof(*cred))) {
syslog(LOG_INFO, "want %lu", CMSG_LEN(sizeof(*cred)));
errmsg = "cmsg";
goto sockerror;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment