dup2: Fix return value with oldfd == newfd and invalid fd
commit80500d2f76c487cab0a82747e13bd1944f5f52e1
authorJeff Mahoney <jeffm@suse.com>
Mon, 11 May 2009 18:25:34 +0000 (11 14:25 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 18 May 2009 23:34:44 +0000 (18 16:34 -0700)
tree9ed7e50ffcc4e298199c31461c477c01054ad993
parent0a94a87b54e5c7ee20b42d17108f78eda6c1fe01
dup2: Fix return value with oldfd == newfd and invalid fd

commit 2b79bc4f7ebbd5af3c8b867968f9f15602d5f802 upstream.

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 6c5d0512a091480c9f981162227fdb1c9d70e555 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>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/fcntl.c