Fix alignment problem on AMD64.

Reported by:	Pascal Hofstee <caelian__at__gmail.com>
Submitted by:	Michael Bushkov <bushman__at__rsu.ru>
Tested by:	Pascal Hofstee <caelian__at__gmail.com>
This commit is contained in:
Hajimu UMEMOTO 2006-05-02 23:02:32 +00:00
parent 193599122f
commit b947683ce1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=158257
3 changed files with 20 additions and 16 deletions

View File

@ -151,19 +151,19 @@ send_credentials(struct cached_connection_ *connection, int type)
struct { struct {
struct cmsghdr hdr; struct cmsghdr hdr;
struct cmsgcred creds; char cred[CMSG_SPACE(sizeof(struct cmsgcred))];
} cmsg; } cmsg;
memset(&cmsg, 0, sizeof(cmsg)); 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_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_CREDS; cmsg.hdr.cmsg_type = SCM_CREDS;
memset(&cred_hdr, 0, sizeof(struct msghdr)); memset(&cred_hdr, 0, sizeof(struct msghdr));
cred_hdr.msg_iov = &iov; cred_hdr.msg_iov = &iov;
cred_hdr.msg_iovlen = 1; cred_hdr.msg_iovlen = 1;
cred_hdr.msg_control = &cmsg; cred_hdr.msg_control = (caddr_t)&cmsg;
cred_hdr.msg_controllen = sizeof(cmsg); cred_hdr.msg_controllen = CMSG_SPACE(sizeof(struct cmsgcred));
iov.iov_base = &type; iov.iov_base = &type;
iov.iov_len = sizeof(int); iov.iov_len = sizeof(int);

View File

@ -154,11 +154,12 @@ on_query_startup(struct query_state *qstate)
{ {
struct msghdr cred_hdr; struct msghdr cred_hdr;
struct iovec iov; struct iovec iov;
struct cmsgcred *cred;
int elem_type; int elem_type;
struct { struct {
struct cmsghdr hdr; struct cmsghdr hdr;
struct cmsgcred creds; char cred[CMSG_SPACE(sizeof(struct cmsgcred))];
} cmsg; } cmsg;
TRACE_IN(on_query_startup); TRACE_IN(on_query_startup);
@ -167,8 +168,8 @@ on_query_startup(struct query_state *qstate)
memset(&cred_hdr, 0, sizeof(struct msghdr)); memset(&cred_hdr, 0, sizeof(struct msghdr));
cred_hdr.msg_iov = &iov; cred_hdr.msg_iov = &iov;
cred_hdr.msg_iovlen = 1; cred_hdr.msg_iovlen = 1;
cred_hdr.msg_control = &cmsg; cred_hdr.msg_control = (caddr_t)&cmsg;
cred_hdr.msg_controllen = sizeof(cmsg); cred_hdr.msg_controllen = CMSG_LEN(sizeof(struct cmsgcred));
memset(&iov, 0, sizeof(struct iovec)); memset(&iov, 0, sizeof(struct iovec));
iov.iov_base = &elem_type; iov.iov_base = &elem_type;
@ -179,15 +180,16 @@ on_query_startup(struct query_state *qstate)
return (-1); return (-1);
} }
if (cmsg.hdr.cmsg_len != sizeof cmsg if (cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(struct cmsgcred))
|| cmsg.hdr.cmsg_level != SOL_SOCKET || cmsg.hdr.cmsg_level != SOL_SOCKET
|| cmsg.hdr.cmsg_type != SCM_CREDS) { || cmsg.hdr.cmsg_type != SCM_CREDS) {
TRACE_OUT(on_query_startup); TRACE_OUT(on_query_startup);
return (-1); return (-1);
} }
qstate->uid = cmsg.creds.cmcred_uid; cred = (struct cmsgcred *)CMSG_DATA(&cmsg);
qstate->gid = cmsg.creds.cmcred_gid; qstate->uid = cred->cmcred_uid;
qstate->gid = cred->cmcred_gid;
#if defined(NS_CACHED_EID_CHECKING) || defined(NS_STRICT_CACHED_EID_CHECKING) #if defined(NS_CACHED_EID_CHECKING) || defined(NS_STRICT_CACHED_EID_CHECKING)
/* /*

View File

@ -154,11 +154,12 @@ on_query_startup(struct query_state *qstate)
{ {
struct msghdr cred_hdr; struct msghdr cred_hdr;
struct iovec iov; struct iovec iov;
struct cmsgcred *cred;
int elem_type; int elem_type;
struct { struct {
struct cmsghdr hdr; struct cmsghdr hdr;
struct cmsgcred creds; char cred[CMSG_SPACE(sizeof(struct cmsgcred))];
} cmsg; } cmsg;
TRACE_IN(on_query_startup); TRACE_IN(on_query_startup);
@ -167,8 +168,8 @@ on_query_startup(struct query_state *qstate)
memset(&cred_hdr, 0, sizeof(struct msghdr)); memset(&cred_hdr, 0, sizeof(struct msghdr));
cred_hdr.msg_iov = &iov; cred_hdr.msg_iov = &iov;
cred_hdr.msg_iovlen = 1; cred_hdr.msg_iovlen = 1;
cred_hdr.msg_control = &cmsg; cred_hdr.msg_control = (caddr_t)&cmsg;
cred_hdr.msg_controllen = sizeof(cmsg); cred_hdr.msg_controllen = CMSG_LEN(sizeof(struct cmsgcred));
memset(&iov, 0, sizeof(struct iovec)); memset(&iov, 0, sizeof(struct iovec));
iov.iov_base = &elem_type; iov.iov_base = &elem_type;
@ -179,15 +180,16 @@ on_query_startup(struct query_state *qstate)
return (-1); return (-1);
} }
if (cmsg.hdr.cmsg_len != sizeof cmsg if (cmsg.hdr.cmsg_len < CMSG_LEN(sizeof(struct cmsgcred))
|| cmsg.hdr.cmsg_level != SOL_SOCKET || cmsg.hdr.cmsg_level != SOL_SOCKET
|| cmsg.hdr.cmsg_type != SCM_CREDS) { || cmsg.hdr.cmsg_type != SCM_CREDS) {
TRACE_OUT(on_query_startup); TRACE_OUT(on_query_startup);
return (-1); return (-1);
} }
qstate->uid = cmsg.creds.cmcred_uid; cred = (struct cmsgcred *)CMSG_DATA(&cmsg);
qstate->gid = cmsg.creds.cmcred_gid; qstate->uid = cred->cmcred_uid;
qstate->gid = cred->cmcred_gid;
#if defined(NS_CACHED_EID_CHECKING) || defined(NS_STRICT_CACHED_EID_CHECKING) #if defined(NS_CACHED_EID_CHECKING) || defined(NS_STRICT_CACHED_EID_CHECKING)
/* /*