summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2008-07-26 19:38:19 +0200
committerAl Viro <viro@zeniv.linux.org.uk>2008-07-27 02:53:44 +0200
commit6c5d0512a091480c9f981162227fdb1c9d70e555 (patch)
treed9706cc3c26beacd588a9b976bb4384369a2b86d
parent[PATCH] remove remaining namei_{32,64}.h crap (diff)
downloadlinux-6c5d0512a091480c9f981162227fdb1c9d70e555.tar.xz
linux-6c5d0512a091480c9f981162227fdb1c9d70e555.zip
[PATCH] get rid of corner case in dup3() entirely
Since Ulrich is OK with getting rid of dup3(fd, fd, flags) completely, to hell the damn thing goes. Corner case for dup2() is handled in sys_dup2() (complete with -EBADF if dup2(fd, fd) is called with fd that is not open), the rest is done in dup3(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/fcntl.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c
index ce12a6885115..3deec9887089 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -135,18 +135,12 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
if ((flags & ~O_CLOEXEC) != 0)
return -EINVAL;
+ if (unlikely(oldfd == newfd))
+ return -EINVAL;
+
spin_lock(&files->file_lock);
if (!(file = fcheck(oldfd)))
goto out_unlock;
- err = newfd;
- if (unlikely(newfd == oldfd)) {
- if (flags & O_CLOEXEC) {
- fdt = files_fdtable(files);
- FD_SET(newfd, fdt->close_on_exec);
- }
- goto out_unlock;
- }
- err = -EBADF;
if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out_unlock;
get_file(file); /* We are now finished with oldfd */
@@ -194,6 +188,14 @@ out_fput:
asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)
{
+ if (unlikely(newfd == oldfd)) { /* corner case */
+ struct files_struct *files = current->files;
+ rcu_read_lock();
+ if (!fcheck_files(files, oldfd))
+ oldfd = -EBADF;
+ rcu_read_unlock();
+ return oldfd;
+ }
return sys_dup3(oldfd, newfd, 0);
}