Skip to content

Commit

Permalink
[PATCH] get rid of corner case in dup3() entirely
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Al Viro committed Jul 27, 2008
1 parent 4cc38a1 commit 6c5d051
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -194,6 +188,14 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)

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);
}

Expand Down

0 comments on commit 6c5d051

Please sign in to comment.