Skip to content

Commit 2b79bc4

Browse files
jeffmahoneytorvalds
authored andcommitted
dup2: Fix return value with oldfd == newfd and invalid fd
The return value of dup2 when oldfd == newfd and the fd isn't valid is not getting properly sign extended. We end up with 4294967287 instead of -EBADF. I've reproduced this on SLE11 (2.6.27.21), openSUSE Factory (2.6.29-rc5), and Ubuntu 9.04 (2.6.28). This patch uses a signed int for the error value so it is properly extended. Commit 6c5d051 introduced this regression. Reported-by: Jiri Dluhos <jdluhos@novell.com> Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fd18de5 commit 2b79bc4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎fs/fcntl.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd)
117117
{
118118
if (unlikely(newfd == oldfd)) { /* corner case */
119119
struct files_struct *files = current->files;
120+
int retval = oldfd;
121+
120122
rcu_read_lock();
121123
if (!fcheck_files(files, oldfd))
122-
oldfd = -EBADF;
124+
retval = -EBADF;
123125
rcu_read_unlock();
124-
return oldfd;
126+
return retval;
125127
}
126128
return sys_dup3(oldfd, newfd, 0);
127129
}

0 commit comments

Comments
 (0)