[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test-dup3.c:108: assertion failed (was: Re: test-cloexec.c:97: asser

From: Richard W.M. Jones
Subject: Re: test-dup3.c:108: assertion failed (was: Re: test-cloexec.c:97: assertion failed)
Date: Tue, 9 Oct 2012 15:12:21 +0100
User-agent: Mutt/1.5.20 (2009-12-10)

I'm testing the following patch.


From 0944e30e12dec6544b3602626b60ff412375c78f Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <address@hidden>
Date: Tue, 9 Oct 2012 14:42:45 +0100
Subject: [PATCH] dup3: Return an error when oldfd == newfd.

The following commit:

  commit fe17f22d7fd0e344ef6447238f799bb49f670c6f
  Author: Al Viro <address@hidden>
  Date:   Tue Aug 21 11:48:11 2012 -0400

    take purely descriptor-related stuff from fcntl.c to file.c

was supposed to be just code motion, but it dropped the following two

  if (unlikely(oldfd == newfd))
          return -EINVAL;

from the dup3 system call.  dup3 is not specified by POSIX, so Linux
can do what it likes.  However the POSIX proposal for dup3 [1] states
that it should return an error if oldfd == newfd.

[1] http://austingroupbugs.net/view.php?id=411

Signed-off-by: Richard W.M. Jones <address@hidden>
 fs/file.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/file.c b/fs/file.c
index 0f1bda4..d3b5fa8 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -922,6 +922,9 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, 
newfd, int, flags)
        if ((flags & ~O_CLOEXEC) != 0)
                return -EINVAL;
+       if (unlikely(oldfd == newfd))
+               return -EINVAL;
        if (newfd >= rlimit(RLIMIT_NOFILE))
                return -EMFILE;

Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]