summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2009-08-27 16:19:27 +0000
committermillert <millert@openbsd.org>2009-08-27 16:19:27 +0000
commit5fe0ba81f0af9da36004a9f6ec81c71350730de5 (patch)
tree7aea7d1de7332ff0e2207de5125b9e53d3f83f37 /lib/libc
parentMore iscsi defines needed. (diff)
downloadwireguard-openbsd-5fe0ba81f0af9da36004a9f6ec81c71350730de5.tar.xz
wireguard-openbsd-5fe0ba81f0af9da36004a9f6ec81c71350730de5.zip
Don't stop traversing a directory hierarchy if we reach SHRT_MAX,
just stop updating fts_level so we don't overflow it. This allows rm, find, etc to operate on very deep hierarchies. Consumers of fts(3) do need to be aware that the actual level may be larger than fts_level. During the next libc major bump we will make fts_level an int instead of a short. OK deraadt@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/fts.323
-rw-r--r--lib/libc/gen/fts.c18
2 files changed, 27 insertions, 14 deletions
diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3
index cd6bdb78e5d..967346efcd4 100644
--- a/lib/libc/gen/fts.3
+++ b/lib/libc/gen/fts.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: fts.3,v 1.25 2009/03/23 22:57:36 sobrado Exp $
+.\" $OpenBSD: fts.3,v 1.26 2009/08/27 16:19:27 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)fts.3 8.5 (Berkeley) 4/16/94
.\"
-.Dd $Mdocdate: March 23 2009 $
+.Dd $Mdocdate: August 27 2009 $
.Dt FTS 3
.Os
.Sh NAME
@@ -230,10 +230,25 @@ was found.
The
.Li FTSENT
structure representing the parent of the starting point (or root)
-of the traversal is numbered \-1, and the
+of the traversal is numbered
+.Ev FTS_PARENTLEVEL
+(\-1), and the
.Li FTSENT
structure for the root
-itself is numbered 0.
+itself is numbered
+.Ev FTS_ROOTLEVEL
+(0).
+Note that while
+.Fa fts_level
+cannot hold a number of levels greater than
+.Ev FTS_MAXLEVEL ,
+the
+.Nm
+functions themselves are not limited to a fixed number
+of levels.
+Application code that inspects
+.Fa fts_level
+should be written with this in mind.
.It Fa fts_errno
Upon return of an
.Li FTSENT
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 62b815fd2f0..bbc1dc7475b 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fts.c,v 1.42 2009/02/11 13:24:05 otto Exp $ */
+/* $OpenBSD: fts.c,v 1.43 2009/08/27 16:19:27 millert Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -633,15 +633,13 @@ fts_build(FTS *sp, int type)
len++;
maxlen = sp->fts_pathlen - len;
- if (cur->fts_level == SHRT_MAX) {
- (void)closedir(dirp);
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
- errno = ENAMETOOLONG;
- return (NULL);
- }
-
- level = cur->fts_level + 1;
+ /*
+ * fts_level is a short so we must prevent it from wrapping
+ * around to FTS_ROOTLEVEL and FTS_ROOTPARENTLEVEL.
+ */
+ level = cur->fts_level;
+ if (level < FTS_MAXLEVEL)
+ level++;
/* Read the directory, attaching each entry to the `link' pointer. */
doadjust = 0;