summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-03-14 01:03:29 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-03-14 01:03:29 +0100
commite5606e5afa828257d31dab5a928a5bb52ab7a72b (patch)
tree595ec2e9451c804a3a0a40a031e88d0e66ace2f0
parentbec6c9c75ab9d752ffaafc34de404a5780e4a051 (diff)
parent89acbfeac418cb3b9671e533919885cf458b0a90 (diff)
Merge commit 'refs/top-bases/tschwinge/Roger_Whittaker' into tschwinge/Roger_Whittakerglibc-2.19-hurd+libpthread-20160518
-rw-r--r--sysdeps/mach/hurd/recvmsg.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c
index 71ba20e0f6..0c8b89d17b 100644
--- a/sysdeps/mach/hurd/recvmsg.c
+++ b/sysdeps/mach/hurd/recvmsg.c
@@ -158,6 +158,7 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
char *buf;
int nfds, *opened_fds = NULL;
int i, ii, j;
+ int newfds;
error_t reauthenticate (mach_port_t port, mach_port_t *result)
{
@@ -280,6 +281,8 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
/* This counts how many ports we processed completely. */
i = 0;
+ /* This counts how many new fds we create. */
+ newfds = 0;
for (cmsg = CMSG_FIRSTHDR (message);
cmsg;
@@ -295,17 +298,19 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
for (j = 0; j < nfds; j++)
{
- err = reauthenticate (ports[i], &newports[i]);
+ err = reauthenticate (ports[i], &newports[newfds]);
if (err)
goto cleanup;
- fds[j] = opened_fds[i] = _hurd_intern_fd (newports[i], fds[j], 0);
+ fds[j] = opened_fds[newfds] = _hurd_intern_fd (newports[newfds],
+ fds[j], 0);
if (fds[j] == -1)
{
err = errno;
- __mach_port_deallocate (__mach_task_self (), newports[i]);
+ __mach_port_deallocate (__mach_task_self (), newports[newfds]);
goto cleanup;
}
i++;
+ newfds++;
}
}
else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS)
@@ -337,7 +342,7 @@ cleanup:
if (nports > 0)
{
ii = 0;
- j = 0;
+ newfds = 0;
for (cmsg = CMSG_FIRSTHDR (message);
cmsg;
cmsg = CMSG_NXTHDR (message, cmsg))
@@ -346,16 +351,17 @@ cleanup:
{
nfds = (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
/ sizeof (int);
- for (j = 0; j < nfds && ii < i; j++, ii++)
+ for (j = 0; j < nfds && ii < i; j++, ii++, newfds++)
{
- _hurd_fd_close (_hurd_fd_get (opened_fds[ii]));
- __mach_port_deallocate (__mach_task_self (), newports[ii]);
+ _hurd_fd_close (_hurd_fd_get (opened_fds[newfds]));
+ __mach_port_deallocate (__mach_task_self (), newports[newfds]);
__mach_port_deallocate (__mach_task_self (), ports[ii]);
}
}
else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS)
{
__mach_port_deallocate (__mach_task_self (), ports[ii]);
+ ii++;
}
}
}