Skip to content

Commit

Permalink
ipc_us: slightly more robust cmsg handling
Browse files Browse the repository at this point in the history
Cope with multiple cmsg structures in the received msg.
  • Loading branch information
Jeremy Fitzhardinge committed Sep 6, 2012
1 parent 6d75ccb commit 20a7075
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/ipc_us.c
Expand Up @@ -856,16 +856,19 @@ qb_ipcs_uc_recv_and_auth(int32_t sock, void *msg, size_t len,
*/
{
struct ucred cred;
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg_recv);
assert(cmsg != NULL);
if (CMSG_DATA(cmsg)) {
struct cmsghdr *cmsg;

res = -EINVAL;
for (cmsg = CMSG_FIRSTHDR(&msg_recv); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg_recv, cmsg)) {
if (cmsg->cmsg_type != SCM_CREDENTIALS)
continue;

memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct ucred));
res = 0;
ugp->pid = cred.pid;
ugp->uid = cred.uid;
ugp->gid = cred.gid;
} else {
res = -EINVAL;
break;
}
}
#else /* no credentials */
Expand Down

0 comments on commit 20a7075

Please sign in to comment.