[BZ,16852] Do not clobber recvmmsg argument.

Message ID 20140428152937.GA1736@domone.podge
State Superseded
Headers

Commit Message

Ondrej Bilka April 28, 2014, 3:29 p.m. UTC
  Hi, here Rich asked about intended behaviour of recvmmsg timeout
argument. A kernel overwrites it by remaining time but we declare it
with const argument. So who is correct?

If we want to make timeout constant following patch should work.

Comments?

	* sysdeps/unix/sysv/linux/recvmmsg.c (recvmmsg): Do not clobber
	timeout argument.
  

Comments

Andreas Schwab April 28, 2014, 3:40 p.m. UTC | #1
Ondřej Bílka <neleai@seznam.cz> writes:

> +  struct timespec dummy;
> +  memcpy (&dummy, tmo, sizeof (struct timespec));

What's wrong with an assignment?

>    if (SINGLE_THREAD_P)
>      return INLINE_SYSCALL (recvmmsg, 5, fd, vmessages, vlen, flags, tmo);

You still pass a const where a non-const is expected.

Andreas.
  

Patch

diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
index 57ddf31..56690ff 100644
--- a/sysdeps/unix/sysv/linux/recvmmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmmsg.c
@@ -37,6 +37,10 @@  int
 recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
 	  const struct timespec *tmo)
 {
+  struct timespec dummy;
+  memcpy (&dummy, tmo, sizeof (struct timespec));
+  tmo = &dummy;
+
   if (SINGLE_THREAD_P)
     return INLINE_SYSCALL (recvmmsg, 5, fd, vmessages, vlen, flags, tmo);
 
@@ -61,6 +65,10 @@  int
 recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
 	  const struct timespec *tmo)
 {
+  struct timespec dummy;
+  memcpy (&dummy, tmo, sizeof (struct timespec));
+  tmo = &dummy;
+
   if (__glibc_likely (have_recvmmsg >= 0))
     {
       int ret = __internal_recvmmsg (fd, vmessages, vlen, flags, tmo);