Messages in this thread Patch in this message | | | Date | Mon, 11 May 2009 11:40:56 -0700 (PDT) | From | Linus Torvalds <> | Subject | Re: [PATCH] dup2: Fix return value with oldfd == newfd and invalid fd |
| |
On Mon, 11 May 2009, Jeff Mahoney wrote: > > 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.
Indeed.
> This patch uses a signed int for the error value so it is properly extended.
However, I'd rather move the new variable into the block where it is used, and keep the whole corner-case thing self-contained.
So can you verify that this trivial variation on the patch is ok by you, and I'll commit it as yours with your message? (I realize it's really trivial, and I could just do this myself, but good to get the change ack'ed anyway).
Linus
--- fs/fcntl.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/fcntl.c b/fs/fcntl.c index cc8e4de..1ad7031 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -117,11 +117,13 @@ SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd) { if (unlikely(newfd == oldfd)) { /* corner case */ struct files_struct *files = current->files; + int retval = oldfd; + rcu_read_lock(); if (!fcheck_files(files, oldfd)) - oldfd = -EBADF; + retval = -EBADF; rcu_read_unlock(); - return oldfd; + return retval; } return sys_dup3(oldfd, newfd, 0); }
| |