Date: Sun, 2 Apr 2006 20:43:14 GMT From: Todd Miller <Todd.Miller@courtesan.com> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/95239: nftw() returns EINVAL for large values of maxfds when it should not Message-ID: <200604022043.k32KhEGU082448@www.freebsd.org> Resent-Message-ID: <200604022050.k32KoPNg051365@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 95239
>Category: misc
>Synopsis: nftw() returns EINVAL for large values of maxfds when it should not
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sun Apr 02 20:50:24 GMT 2006
>Closed-Date:
>Last-Modified:
>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 inluded 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:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604022043.k32KhEGU082448>
