Unbreak nscd(8). Without this change the CMSG gets truncated.

Reviewed by:	des
MFC after:	2 weeks
Sponsored by:	Chalmers University of Technology
Differential Revision:	https://reviews.freebsd.org/D17452
This commit is contained in:
Edward Tomasz Napierala 2018-11-01 18:19:10 +00:00
parent 49618eacb2
commit 5ae9f69896
2 changed files with 9 additions and 8 deletions

View File

@ -138,14 +138,14 @@ send_credentials(struct nscd_connection_ *connection, int type)
struct msghdr cred_hdr;
struct iovec iov;
struct {
union {
struct cmsghdr hdr;
struct cmsgcred creds;
char cred[CMSG_SPACE(sizeof(struct cmsgcred))];
} cmsg;
TRACE_IN(send_credentials);
memset(&cmsg, 0, sizeof(cmsg));
cmsg.hdr.cmsg_len = sizeof(cmsg);
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_CREDS;
@ -153,7 +153,7 @@ send_credentials(struct nscd_connection_ *connection, int type)
cred_hdr.msg_iov = &iov;
cred_hdr.msg_iovlen = 1;
cred_hdr.msg_control = &cmsg;
cred_hdr.msg_controllen = sizeof(cmsg);
cred_hdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
iov.iov_base = &type;
iov.iov_len = sizeof(int);

View File

@ -160,7 +160,7 @@ on_query_startup(struct query_state *qstate)
struct cmsgcred *cred;
int elem_type;
struct {
union {
struct cmsghdr hdr;
char cred[CMSG_SPACE(sizeof(struct cmsgcred))];
} cmsg;
@ -171,8 +171,8 @@ on_query_startup(struct query_state *qstate)
memset(&cred_hdr, 0, sizeof(struct msghdr));
cred_hdr.msg_iov = &iov;
cred_hdr.msg_iovlen = 1;
cred_hdr.msg_control = (caddr_t)&cmsg;
cred_hdr.msg_controllen = CMSG_LEN(sizeof(struct cmsgcred));
cred_hdr.msg_control = &cmsg;
cred_hdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
memset(&iov, 0, sizeof(struct iovec));
iov.iov_base = &elem_type;
@ -183,7 +183,8 @@ on_query_startup(struct query_state *qstate)
return (-1);
}
if (cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(struct cmsgcred))
if (cred_hdr.msg_controllen < CMSG_LEN(sizeof(struct cmsgcred))
|| cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(struct cmsgcred))
|| cmsg.hdr.cmsg_level != SOL_SOCKET
|| cmsg.hdr.cmsg_type != SCM_CREDS) {
TRACE_OUT(on_query_startup);