summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-03-13 23:26:59 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-03-13 23:26:59 +0100
commit2500bee4e75f89270aef68221b832ff9ce748aae (patch)
tree72e1400a3dd60ea527121978c5e2f41378280817
parent511e7f169aabcd38a25b9d8601b5f034f1ea0589 (diff)
Do not use the same index for ports and for new fds
-rw-r--r--sysdeps/mach/hurd/recvmsg.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c
index 0200b1363e..dfd4145b60 100644
--- a/sysdeps/mach/hurd/recvmsg.c
+++ b/sysdeps/mach/hurd/recvmsg.c
@@ -41,6 +41,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)
{
@@ -163,6 +164,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;
@@ -178,17 +181,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++;
}
}
}
@@ -205,7 +210,7 @@ cleanup:
if (nports > 0)
{
ii = 0;
- j = 0;
+ newfds = 0;
for (cmsg = CMSG_FIRSTHDR (message);
cmsg;
cmsg = CMSG_NXTHDR (message, cmsg))
@@ -214,10 +219,10 @@ 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]);
}
}