Subject: bin/3365: mtree incorrectly modifies file attributes if a
To: None <gnats-bugs@gnats.netbsd.org>
From: None <enami@ba2.so-net.or.jp>
List: netbsd-bugs
Date: 03/20/1997 13:26:29
>Number:         3365
>Category:       bin
>Synopsis:       mtree incorrectly modifies file attributes if a directory and its subdirectory contains subdirectory of same name (i.e; /usr and its subdirectory /usr/src both has subdirectory bin)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 19 20:35:02 1997
>Last-Modified:
>Originator:     enami tsugutomo
>Organization:
	an individual
>Release:        NetBSD-current 1997 Mar. 18
>Environment:
System: NetBSD pavlov.enami.ba2.so-net.or.jp 1.2D NetBSD 1.2D (PAVLOV) #197: Tue Mar 18 12:39:20 JST 1997 enami@pavlov.enami.ba2.so-net.or.jp:/b/netbsd/kernel/compile/PAVLOV i386


>Description:
mtree incorrectly modifies file attributes if a directory and its subdirectory
contains subdirectory of same name (i.e; /usr and its subdirectory /usr/src
both has subdirectory bin)

>How-To-Repeat:
For example, give non-root uid to /usr/src/*, and do mtree with 
/usr/src/etc/mtree/NetBSD.dist (or 4.4BSD.dist).  With my tree, it gives
following result.

plants-doll# mtree -def mtree/NetBSD.dist -p / -u
usr/src/bin: 
        user (0, 1000, modified)
usr/src/games: 
        user (0, 1000, modified)

The directory modified may be differ according to how fts(3) traverse your
directory.

>Fix:
In verfiy() of mtree, when traversing /usr, `src' may found.  Then becase
NetBSD.dist only has spec of `src' itself, it doesn't go down in spec tree,
but it traverses in actual tree.

I think when current node in spec tree (`ep' in function verify()) doesn't
has child and current node in actual tree (`p') is directory, mtree shouldn't
traverse under `p'.

cvs diff: Diffing .
Index: verify.c
===================================================================
RCS file: /a/cvsroot/NetBSD/src/usr.sbin/mtree/verify.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 verify.c
--- verify.c	1996/11/16 10:06:04	1.1.1.1
+++ verify.c	1997/03/20 03:56:41
@@ -119,13 +119,13 @@
 				ep->flags |= F_VISIT;
 				if (compare(ep->name, ep, p))
 					rval = MISMATCHEXIT;
-				if (ep->flags & F_IGN)
-					(void)fts_set(t, p, FTS_SKIP);
-				else if (ep->child && ep->type == F_DIR &&
+				if (!(ep->flags & F_IGN) &&
+				    ep->child && ep->type == F_DIR &&
 				    p->fts_info == FTS_D) {
 					level = ep->child;
 					++specdepth;
-				}
+				} else
+					(void)fts_set(t, p, FTS_SKIP);
 				break;
 			}
 
>Audit-Trail:
>Unformatted: