From e41f43a1a675ee6d0f21f2ab611c97ffe9c22088 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 21 Aug 2009 21:19:45 +0000 Subject: [PATCH] * fcntl.cc (fcntl64): Detect negative fd as error. --- winsup/cygwin/ChangeLog | 4 ++++ winsup/cygwin/fcntl.cc | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9c08c56da..316a48a3e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,7 @@ +2009-08-21 Christopher Faylor + + * fcntl.cc (fcntl64): Detect negative fd as error. + 2009-08-21 Corinna Vinschen * mmap.cc (mmap64): Allocate fh_disk_file on cygheap. Delete diff --git a/winsup/cygwin/fcntl.cc b/winsup/cygwin/fcntl.cc index 442686268..bb41f05c5 100644 --- a/winsup/cygwin/fcntl.cc +++ b/winsup/cygwin/fcntl.cc @@ -40,7 +40,13 @@ fcntl64 (int fd, int cmd, ...) switch (cmd) { case F_DUPFD: - res = dup2 (fd, cygheap_fdnew (((int) arg) - 1)); + if ((int) arg >= 0) + res = dup2 (fd, cygheap_fdnew (((int) arg) - 1)); + else + { + set_errno (EINVAL); + res = -1; + } break; case F_GETLK: case F_SETLK: