Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Apr 2012 14:08:10 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r234131 - in head: lib/libc/sys sys/kern
Message-ID:  <201204111408.q3BE8A3x080941@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Apr 11 14:08:09 2012
New Revision: 234131
URL: http://svn.freebsd.org/changeset/base/234131

Log:
  Return EBADF instead of EMFILE from dup2 when the second argument is
  outside the range of valid file descriptors
  
  PR:		kern/164970
  Submitted by:	Peter Jeremy <peterjeremy@acm.org>
  Reviewed by:	jilles
  Approved by:	cperciva
  MFC after:	1 week

Modified:
  head/lib/libc/sys/dup.2
  head/lib/libc/sys/fcntl.2
  head/sys/kern/kern_descrip.c

Modified: head/lib/libc/sys/dup.2
==============================================================================
--- head/lib/libc/sys/dup.2	Wed Apr 11 12:26:30 2012	(r234130)
+++ head/lib/libc/sys/dup.2	Wed Apr 11 14:08:09 2012	(r234131)
@@ -128,20 +128,27 @@ indicates the cause of the error.
 .Sh ERRORS
 The
 .Fn dup
-and
-.Fn dup2
-system calls fail if:
+system call fails if:
 .Bl -tag -width Er
 .It Bq Er EBADF
 The
 .Fa oldd
-or
-.Fa newd
 argument
 is not a valid active descriptor
 .It Bq Er EMFILE
 Too many descriptors are active.
 .El
+The
+.Fn dup2
+system call fails if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+The
+.Fa oldd
+argument is not a valid active descriptor or the
+.Fa newd
+argument is negative or exceeds the maximum allowable descriptor number
+.El
 .Sh SEE ALSO
 .Xr accept 2 ,
 .Xr cap_new 2 ,

Modified: head/lib/libc/sys/fcntl.2
==============================================================================
--- head/lib/libc/sys/fcntl.2	Wed Apr 11 12:26:30 2012	(r234130)
+++ head/lib/libc/sys/fcntl.2	Wed Apr 11 14:08:09 2012	(r234131)
@@ -539,8 +539,6 @@ The argument
 .Fa cmd
 is
 .Dv F_DUPFD
-or
-.Dv F_DUP2FD
 and the maximum number of file descriptors permitted for the
 process are already in use,
 or no file descriptors greater than or equal to

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Wed Apr 11 12:26:30 2012	(r234130)
+++ head/sys/kern/kern_descrip.c	Wed Apr 11 14:08:09 2012	(r234131)
@@ -817,7 +817,7 @@ do_dup(struct thread *td, int flags, int
 	maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
 	PROC_UNLOCK(p);
 	if (new >= maxfd)
-		return (flags & DUP_FCNTL ? EINVAL : EMFILE);
+		return (flags & DUP_FCNTL ? EINVAL : EBADF);
 
 	FILEDESC_XLOCK(fdp);
 	if (old >= fdp->fd_nfiles || fdp->fd_ofiles[old] == NULL) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204111408.q3BE8A3x080941>