aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-10-09 10:27:43 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-10-09 23:33:38 -0400
commitaed976475bff939672b0e21595839c445dcec0fa (patch)
treea260411639546dad441bf6060be123ca0842a31c /fs
parentd1c7d97ad58836affde6e39980b96527510b572e (diff)
dup3: Return an error when oldfd == newfd.
I have tested the attached patch to fix the dup3 regression. Rich. From 0944e30e12dec6544b3602626b60ff412375c78f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" <rjones@redhat.com> 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 <viro@zeniv.linux.org.uk> 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 lines: 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 <rjones@redhat.com> Tested-by: Richard W.M. Jones <rjones@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/file.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/fs/file.c b/fs/file.c
index 0f1bda4bebf..d3b5fa80b71 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -922,6 +922,9 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
922 if ((flags & ~O_CLOEXEC) != 0) 922 if ((flags & ~O_CLOEXEC) != 0)
923 return -EINVAL; 923 return -EINVAL;
924 924
925 if (unlikely(oldfd == newfd))
926 return -EINVAL;
927
925 if (newfd >= rlimit(RLIMIT_NOFILE)) 928 if (newfd >= rlimit(RLIMIT_NOFILE))
926 return -EMFILE; 929 return -EMFILE;
927 930