From nobody@FreeBSD.org  Sun Apr  2 20:43:15 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 02E3816A45F
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Apr 2006 20:43:15 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A78EB43D48
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Apr 2006 20:43:14 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k32KhEsw082449
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 2 Apr 2006 20:43:14 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k32KhEGU082448;
	Sun, 2 Apr 2006 20:43:14 GMT
	(envelope-from nobody)
Message-Id: <200604022043.k32KhEGU082448@www.freebsd.org>
Date: Sun, 2 Apr 2006 20:43:14 GMT
From: Todd Miller <Todd.Miller@courtesan.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: nftw() returns EINVAL for large values of maxfds when it should not
X-Send-Pr-Version: www-2.3

>Number:         95239
>Category:       kern
>Synopsis:       [libc] [patch] nftw(3) returns EINVAL for large values of maxfds when it should not
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 02 20:50:24 GMT 2006
>Closed-Date:    Mon Dec 17 13:42:05 UTC 2012
>Last-Modified:  Mon Dec 17 13:42:05 UTC 2012
>Originator:     Todd Miller
>Release:        
>Organization:
>Environment:
>Description:
The nftw(3) I wrote for OpenBSD that is now used by FreeBSD has a bug
where it returns -1 and sets errno to EINVAL when maxfds > OPEN_MAX.
However, only the older ftw(3) should have this restriction (see single
unix or POSIX).

I've included the fix I used in OpenBSD but due to the web form submission
the patch will likely have to be applied by hand (it is small).
>How-To-Repeat:

>Fix:
Index: ftw.3
===================================================================
RCS file: /home/cvs/freebsd/src/lib/libc/gen/ftw.3,v
retrieving revision 1.3
diff -u -r1.3 ftw.3
--- ftw.3       23 Nov 2005 15:41:36 -0000      1.3
+++ ftw.3       2 Apr 2006 20:37:44 -0000
@@ -185,7 +185,10 @@
 .It Bq Er EINVAL
 The
 .Fa maxfds
-argument is less than 1.
+argument is less than 1 or, in the case of
+.Nm ftw
+only, greater than
+.Dv OPEN_MAX .
 .El
 .Sh SEE ALSO
 .Xr chdir 2 ,
Index: nftw.c
===================================================================
RCS file: /home/cvs/freebsd/src/lib/libc/gen/nftw.c,v
retrieving revision 1.1
diff -u -r1.1 nftw.c
--- nftw.c      24 Aug 2004 13:00:55 -0000      1.1
+++ nftw.c      2 Apr 2006 20:37:07 -0000
@@ -34,7 +34,6 @@
 #include <errno.h>
 #include <fts.h>
 #include <ftw.h>
-#include <limits.h>
 
 int
 nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
@@ -47,7 +46,7 @@
        int error = 0, ftsflags, fnflag, postorder, sverrno;
 
        /* XXX - nfds is currently unused */
-       if (nfds < 1 || nfds > OPEN_MAX) {
+       if (nfds < 1) {
                errno = EINVAL;
                return (-1);
        }
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: Todd Miller <Todd.Miller@courtesan.com>
Cc: freebsd-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject: Re: misc/95239: nftw() returns EINVAL for large values of maxfds
 when it should not
Date: Tue, 4 Apr 2006 16:07:02 +1000 (EST)

 It is a bug for anything to have a limit of OPEN_MAX for anything.
 The POSIX limit for everything that has a limit on open files, including
 ftw, is {OPEN_MAX} is quite different.  It is a bug for BSD systems
 to define OPEN_MAX, since defining OPEN_MAX says that the limit on
 open files is a compile-time constant but it is actually a runtime
 constant and highly variable.  On FreeBSD at least, {OPEN_MAX} =
 sysconf(_SC_OPEN_MAX) is the associated rlimit.
 
 Bruce

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/95239: commit references a PR
Date: Thu,  9 Aug 2012 15:04:21 +0000 (UTC)

 Author: jilles
 Date: Thu Aug  9 15:04:06 2012
 New Revision: 239150
 URL: http://svn.freebsd.org/changeset/base/239150
 
 Log:
   nftw(): Do not check the maxfds argument against OPEN_MAX.
   
   Apart from the fact that nothing should have OPEN_MAX as a limit (as opposed
   to RLIMIT_NOFILE from getrlimit() or _SC_OPEN_MAX from sysconf()), POSIX
   does not require us to check this.
   
   PR:		95239
   Submitted by:	Todd Miller
 
 Modified:
   head/lib/libc/gen/nftw.c
 
 Modified: head/lib/libc/gen/nftw.c
 ==============================================================================
 --- head/lib/libc/gen/nftw.c	Thu Aug  9 14:46:52 2012	(r239149)
 +++ head/lib/libc/gen/nftw.c	Thu Aug  9 15:04:06 2012	(r239150)
 @@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
  #include <errno.h>
  #include <fts.h>
  #include <ftw.h>
 -#include <limits.h>
  
  int
  nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
 @@ -47,7 +46,7 @@ nftw(const char *path, int (*fn)(const c
  	int error = 0, ftsflags, fnflag, postorder, sverrno;
  
  	/* XXX - nfds is currently unused */
 -	if (nfds < 1 || nfds > OPEN_MAX) {
 +	if (nfds < 1) {
  		errno = EINVAL;
  		return (-1);
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/95239: commit references a PR
Date: Thu,  9 Aug 2012 15:11:51 +0000 (UTC)

 Author: jilles
 Date: Thu Aug  9 15:11:38 2012
 New Revision: 239151
 URL: http://svn.freebsd.org/changeset/base/239151
 
 Log:
   ftw(): Do not check the maxfds argument against OPEN_MAX.
   
   Apart from the fact that nothing should have OPEN_MAX as a limit (as opposed
   to RLIMIT_NOFILE from getrlimit() or _SC_OPEN_MAX from sysconf()), POSIX
   does not require us to check this. POSIX does have a requirement on the
   application that maxfds not exceed {OPEN_MAX}, but does not require the
   implementation to check it ("may fail").
   
   PR:		95239
 
 Modified:
   head/lib/libc/gen/ftw.c
 
 Modified: head/lib/libc/gen/ftw.c
 ==============================================================================
 --- head/lib/libc/gen/ftw.c	Thu Aug  9 15:04:06 2012	(r239150)
 +++ head/lib/libc/gen/ftw.c	Thu Aug  9 15:11:38 2012	(r239151)
 @@ -28,7 +28,6 @@ __FBSDID("$FreeBSD$");
  #include <errno.h>
  #include <fts.h>
  #include <ftw.h>
 -#include <limits.h>
  
  int
  ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
 @@ -40,7 +39,7 @@ ftw(const char *path, int (*fn)(const ch
  	int error = 0, fnflag, sverrno;
  
  	/* XXX - nfds is currently unused */
 -	if (nfds < 1 || nfds > OPEN_MAX) {
 +	if (nfds < 1) {
  		errno = EINVAL;
  		return (-1);
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Thu Aug 9 15:39:49 UTC 2012 
State-Changed-Why:  
Fixed in 10-current. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Thu Aug 9 15:39:49 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=95239 
State-Changed-From-To: patched->closed 
State-Changed-By: jilles 
State-Changed-When: Mon Dec 17 13:41:40 UTC 2012 
State-Changed-Why:  
Fixed in 10-current and 9-stable, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=95239 
>Unformatted:
