From nobody@FreeBSD.org  Tue Mar  2 04:32:00 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 59B881065690
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  2 Mar 2010 04:32:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 30B838FC32
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  2 Mar 2010 04:32:00 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o224W0RR008730
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 2 Mar 2010 04:32:00 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o224VxH1008729;
	Tue, 2 Mar 2010 04:31:59 GMT
	(envelope-from nobody)
Message-Id: <201003020431.o224VxH1008729@www.freebsd.org>
Date: Tue, 2 Mar 2010 04:31:59 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: mtree(8) doesn't reject non-regular files for -X
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144411
>Category:       bin
>Synopsis:       [patch] mtree(8) doesn't reject non-regular files for -X
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 02 04:40:02 UTC 2010
>Closed-Date:    Sat Oct 16 10:06:19 UTC 2010
>Last-Modified:  Sun Feb 03 22:28:09 UTC 2013
>Originator:     Garrett Cooper
>Release:        RELENG_8
>Organization:
Cisco Systems, Inc
>Environment:
FreeBSD garrcoop-fbsd.cisco.com 8.0-STABLE FreeBSD 8.0-STABLE #2: Wed Feb  3 16:57:07 PST 2010     garrcoop@garrcoop-fbsd.cisco.com:/usr/obj/usr/src/sys/LAPPY_X86  i386
>Description:
Didn't fully read the manpage for mtree(8), and I assumed that -X accepted exclusion arguments like tar does.

Turns out that wasn't the case, and mtree hangs when given directories via -X:

[root@garrcoop-fbsd /usr/home/garrcoop/head/tools/regression/lib/libc/gen]# mtree -X /boot/
^C

The patch attached does a stat(2) on the file first to ensure that the resolved file is in fact legitimate, then proceeds to poke at the file to make sure that it's a regular file.

This is a draft patch and can and will be revised if necessary..
>How-To-Repeat:
mtree -X /boot
>Fix:
See proposed patch attached.

Patch attached with submission follows:

Index: excludes.c
===================================================================
--- excludes.c	(revision 204532)
+++ excludes.c	(working copy)
@@ -31,6 +31,7 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/time.h>		/* XXX for mtree.h */
 #include <sys/queue.h>
 
@@ -39,6 +40,7 @@
 #include <fts.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include "mtree.h"		/* XXX for extern.h */
 #include "extern.h"
@@ -66,10 +68,23 @@
 	FILE *fp;
 	char *line, *str;
 	struct exclude *e;
+	struct stat exclude_stat;
 	size_t len;
 
+	/* Let's resolve the name via stat(2) so symlinks to files pass. */
+	if (stat(name, &exclude_stat) < 0) {
+		err(1, "%s", name);
+	}
+	/* Don't let certain files like directories, fifos, etc pass. */
+	if (!S_ISREG(exclude_stat.st_mode)) {
+		/* Make the error message make sense for the directory error
+		 * case. All other values can be EINVAL. */
+		errno = S_ISDIR(exclude_stat.st_mode) ? EISDIR : EINVAL;
+		err(1, "%s", name);
+	}
+
 	fp = fopen(name, "r");
-	if (fp == 0)
+	if (fp == NULL)
 		err(1, "%s", name);
 
 	while ((line = fgetln(fp, &len)) != 0) {


>Release-Note:
>Audit-Trail:

From: Garrett Cooper <yaneurabeya@gmail.com>
To: bug-followup@FreeBSD.org, gcooper@FreeBSD.org
Cc:  
Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular files for 
	-X
Date: Tue, 30 Mar 2010 01:21:58 -0700

 Hi,
     I'm not 100% satisfied with this patch now. Looking back it fails
 the following case:
 
      -P    Do not follow symbolic links in the file hierarchy, instead con-
            sider the symbolic link itself in any comparisons.  This is the
            default.
 
     I need to add a check for this option to the patch, use stat if
 the `follow links' state is true, otherwise use lstat.
 Thanks,
 -Garrett

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: Bruce Evans <brde@optusnet.com.au>, bug-followup <bug-followup@freebsd.org>
Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular files for 
	-X
Date: Tue, 30 Mar 2010 23:46:20 -0700

 On Tue, Mar 30, 2010 at 11:35 PM, Garrett Cooper <yaneurabeya@gmail.com> wrot=
 e:
 > On Tue, Mar 30, 2010 at 5:40 PM, Garrett Cooper <yaneurabeya@gmail.com> wro=
 te:
 >> On Tue, Mar 30, 2010 at 12:12 PM, Bruce Evans <brde@optusnet.com.au> wro=
 te:
 >>> On Wed, 31 Mar 2010, Bruce Evans wrote:
 >>>
 >>>> On Tue, 30 Mar 2010, Garrett Cooper wrote:
 >>>>
 >>>>> Hi,
 >>>>> =A0 =A0I'm not 100% satisfied with this patch now. Looking back it fa=
 ils
 >>>>> the following case:
 >>>>>
 >>>>> =A0 =A0 -P =A0 =A0Do not follow symbolic links in the file hierarchy,=
  instead
 >>>>> con-
 >>>>> =A0 =A0 =A0 =A0 =A0 sider the symbolic link itself in any comparisons=
 . =A0This is the
 >>>>> =A0 =A0 =A0 =A0 =A0 default.
 >>>>
 >>>> -P should have the same semantics and description in all utilities. =
 =A0The
 >>>> description should not have grammar errors like the above (comma splic=
 e).
 >>>> ...
 >>>> I now see that the grammar error is from the original version of mtree=
 (1),
 >>>> and is probably one of the things you don't like. =A0mtree also has -L=
 , but
 >>>> not -R or -P or -h. =A0It is not clear how any utility that traverses =
 trees
 >>>> can work without a full complement of -[HLPR] or how any utility that
 >>>> ...
 >>>
 >>> Looking at the actual patch, I now see that it is about a completely
 >>> different problem. =A0You would only need to understand the amount of
 >>> brokenness of -P to see if you need to use lstat(). =A0I think -P is so
 >>> broken that mtree on symlinks doesn't work at all and not using lstat()
 >>> would be safest.
 >>
 >> Hmmm... so I take it that this is actually the first step in many to
 >> fixing this underlying problem? I suppose I should be opening bugs for
 >> all of the itemized issues that you see in mtree(8) so someone can
 >> submit patches to fix the utility?
 >>
 >>> The patch has some style bugs.
 >>
 >> Please expound on this -- I want to improve my style (without having
 >> to rewrite the entire program of course) -- so that it conforms more
 >> to the projects overall style rules; of course there are some cases
 >> where I can't readily do that (like pkg_install -- ugh), but I'll do
 >> my best to make sure that the rules are withheld.
 >
 > s/withheld/held/
 >
 > I guess the problem was the fact that I didn't use 8-space tabs for
 > first-level tabs? Hard tabs are fine, correct?
 
     Ah, the braces for the single line conditional. Yes, I see what
 you mean now (fixed).
     Also, I see what you mean about -P being broken; mtree(8) uses
 chmod instead of lchmod, chown instead of lchown, etc. This definitely
 needs fixing and I'll assign separate PRs for it.
 Thanks,
 -Garrett

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: Bruce Evans <brde@optusnet.com.au>, bug-followup <bug-followup@freebsd.org>
Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular files for 
	-X
Date: Tue, 30 Mar 2010 23:47:08 -0700

 --005045016abd7713880483131dc3
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 On Tue, Mar 30, 2010 at 11:46 PM, Garrett Cooper <yaneurabeya@gmail.com> wrot=
 e:
 > On Tue, Mar 30, 2010 at 11:35 PM, Garrett Cooper <yaneurabeya@gmail.com> wr=
 ote:
 >> On Tue, Mar 30, 2010 at 5:40 PM, Garrett Cooper <yaneurabeya@gmail.com> wr=
 ote:
 >>> On Tue, Mar 30, 2010 at 12:12 PM, Bruce Evans <brde@optusnet.com.au> wr=
 ote:
 >>>> On Wed, 31 Mar 2010, Bruce Evans wrote:
 >>>>
 >>>>> On Tue, 30 Mar 2010, Garrett Cooper wrote:
 >>>>>
 >>>>>> Hi,
 >>>>>> =A0 =A0I'm not 100% satisfied with this patch now. Looking back it f=
 ails
 >>>>>> the following case:
 >>>>>>
 >>>>>> =A0 =A0 -P =A0 =A0Do not follow symbolic links in the file hierarchy=
 , instead
 >>>>>> con-
 >>>>>> =A0 =A0 =A0 =A0 =A0 sider the symbolic link itself in any comparison=
 s. =A0This is the
 >>>>>> =A0 =A0 =A0 =A0 =A0 default.
 >>>>>
 >>>>> -P should have the same semantics and description in all utilities. =
 =A0The
 >>>>> description should not have grammar errors like the above (comma spli=
 ce).
 >>>>> ...
 >>>>> I now see that the grammar error is from the original version of mtre=
 e(1),
 >>>>> and is probably one of the things you don't like. =A0mtree also has -=
 L, but
 >>>>> not -R or -P or -h. =A0It is not clear how any utility that traverses=
  trees
 >>>>> can work without a full complement of -[HLPR] or how any utility that
 >>>>> ...
 >>>>
 >>>> Looking at the actual patch, I now see that it is about a completely
 >>>> different problem. =A0You would only need to understand the amount of
 >>>> brokenness of -P to see if you need to use lstat(). =A0I think -P is s=
 o
 >>>> broken that mtree on symlinks doesn't work at all and not using lstat(=
 )
 >>>> would be safest.
 >>>
 >>> Hmmm... so I take it that this is actually the first step in many to
 >>> fixing this underlying problem? I suppose I should be opening bugs for
 >>> all of the itemized issues that you see in mtree(8) so someone can
 >>> submit patches to fix the utility?
 >>>
 >>>> The patch has some style bugs.
 >>>
 >>> Please expound on this -- I want to improve my style (without having
 >>> to rewrite the entire program of course) -- so that it conforms more
 >>> to the projects overall style rules; of course there are some cases
 >>> where I can't readily do that (like pkg_install -- ugh), but I'll do
 >>> my best to make sure that the rules are withheld.
 >>
 >> s/withheld/held/
 >>
 >> I guess the problem was the fact that I didn't use 8-space tabs for
 >> first-level tabs? Hard tabs are fine, correct?
 >
 > =A0 =A0Ah, the braces for the single line conditional. Yes, I see what
 > you mean now (fixed).
 > =A0 =A0Also, I see what you mean about -P being broken; mtree(8) uses
 > chmod instead of lchmod, chown instead of lchown, etc. This definitely
 > needs fixing and I'll assign separate PRs for it.
 
 Sorry -- forgot the patch.
 -Garrett
 
 --005045016abd7713880483131dc3
 Content-Type: text/plain; charset=US-ASCII; name="bin.144411.diff.txt"
 Content-Disposition: attachment; filename="bin.144411.diff.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g7frx53q0
 
 CkluZGV4OiBleGNsdWRlcy5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIGV4Y2x1ZGVzLmMJKHJldmlzaW9uIDIw
 NDUzMikKKysrIGV4Y2x1ZGVzLmMJKHdvcmtpbmcgY29weSkKQEAgLTMxLDYgKzMxLDcgQEAKIF9f
 RkJTRElEKCIkRnJlZUJTRCQiKTsKIAogI2luY2x1ZGUgPHN5cy90eXBlcy5oPgorI2luY2x1ZGUg
 PHN5cy9zdGF0Lmg+CiAjaW5jbHVkZSA8c3lzL3RpbWUuaD4JCS8qIFhYWCBmb3IgbXRyZWUuaCAq
 LwogI2luY2x1ZGUgPHN5cy9xdWV1ZS5oPgogCkBAIC0zOSw2ICs0MCw3IEBACiAjaW5jbHVkZSA8
 ZnRzLmg+CiAjaW5jbHVkZSA8c3RkaW8uaD4KICNpbmNsdWRlIDxzdGRsaWIuaD4KKyNpbmNsdWRl
 IDxlcnJuby5oPgogCiAjaW5jbHVkZSAibXRyZWUuaCIJCS8qIFhYWCBmb3IgZXh0ZXJuLmggKi8K
 ICNpbmNsdWRlICJleHRlcm4uaCIKQEAgLTY2LDEwICs2OCwyMyBAQAogCUZJTEUgKmZwOwogCWNo
 YXIgKmxpbmUsICpzdHI7CiAJc3RydWN0IGV4Y2x1ZGUgKmU7CisJc3RydWN0IHN0YXQgZXhjbHVk
 ZV9zdGF0OwogCXNpemVfdCBsZW47CiAKKwkvKiBMZXQncyByZXNvbHZlIHRoZSBuYW1lIHZpYSBz
 dGF0KDIpIHNvIHN5bWxpbmtzIHRvIGZpbGVzIHBhc3MuICovCisJaWYgKHN0YXQobmFtZSwgJmV4
 Y2x1ZGVfc3RhdCkgPCAwKSB7CisJCWVycigxLCAiJXMiLCBuYW1lKTsKKwl9CisJLyogRG9uJ3Qg
 bGV0IGNlcnRhaW4gZmlsZXMgbGlrZSBkaXJlY3RvcmllcywgZmlmb3MsIGV0YyBwYXNzLiAqLwor
 CWlmICghU19JU1JFRyhleGNsdWRlX3N0YXQuc3RfbW9kZSkpIHsKKwkJLyogTWFrZSB0aGUgZXJy
 b3IgbWVzc2FnZSBtYWtlIHNlbnNlIGZvciB0aGUgZGlyZWN0b3J5IGVycm9yCisJCSAqIGNhc2Uu
 IEFsbCBvdGhlciB2YWx1ZXMgY2FuIGJlIEVJTlZBTC4gKi8KKwkJZXJybm8gPSBTX0lTRElSKGV4
 Y2x1ZGVfc3RhdC5zdF9tb2RlKSA/IEVJU0RJUiA6IEVJTlZBTDsKKwkJZXJyKDEsICIlcyIsIG5h
 bWUpOworCX0KKwogCWZwID0gZm9wZW4obmFtZSwgInIiKTsKLQlpZiAoZnAgPT0gMCkKKwlpZiAo
 ZnAgPT0gTlVMTCkKIAkJZXJyKDEsICIlcyIsIG5hbWUpOwogCiAJd2hpbGUgKChsaW5lID0gZmdl
 dGxuKGZwLCAmbGVuKSkgIT0gMCkgewoKCg==
 --005045016abd7713880483131dc3--

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: Bruce Evans <brde@optusnet.com.au>, bug-followup <bug-followup@freebsd.org>
Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular files for 
	-X
Date: Fri, 7 May 2010 00:20:29 -0700

 --005045016ba0d819d70485fbe4b3
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 On Tue, Mar 30, 2010 at 11:47 PM, Garrett Cooper <yaneurabeya@gmail.com> wrot=
 e:
 > On Tue, Mar 30, 2010 at 11:46 PM, Garrett Cooper <yaneurabeya@gmail.com> wr=
 ote:
 >> On Tue, Mar 30, 2010 at 11:35 PM, Garrett Cooper <yaneurabeya@gmail.com> w=
 rote:
 >>> On Tue, Mar 30, 2010 at 5:40 PM, Garrett Cooper <yaneurabeya@gmail.com> w=
 rote:
 >>>> On Tue, Mar 30, 2010 at 12:12 PM, Bruce Evans <brde@optusnet.com.au> w=
 rote:
 >>>>> On Wed, 31 Mar 2010, Bruce Evans wrote:
 >>>>>
 >>>>>> On Tue, 30 Mar 2010, Garrett Cooper wrote:
 >>>>>>
 >>>>>>> Hi,
 >>>>>>> =A0 =A0I'm not 100% satisfied with this patch now. Looking back it =
 fails
 >>>>>>> the following case:
 >>>>>>>
 >>>>>>> =A0 =A0 -P =A0 =A0Do not follow symbolic links in the file hierarch=
 y, instead
 >>>>>>> con-
 >>>>>>> =A0 =A0 =A0 =A0 =A0 sider the symbolic link itself in any compariso=
 ns. =A0This is the
 >>>>>>> =A0 =A0 =A0 =A0 =A0 default.
 >>>>>>
 >>>>>> -P should have the same semantics and description in all utilities. =
 =A0The
 >>>>>> description should not have grammar errors like the above (comma spl=
 ice).
 >>>>>> ...
 >>>>>> I now see that the grammar error is from the original version of mtr=
 ee(1),
 >>>>>> and is probably one of the things you don't like. =A0mtree also has =
 -L, but
 >>>>>> not -R or -P or -h. =A0It is not clear how any utility that traverse=
 s trees
 >>>>>> can work without a full complement of -[HLPR] or how any utility tha=
 t
 >>>>>> ...
 >>>>>
 >>>>> Looking at the actual patch, I now see that it is about a completely
 >>>>> different problem. =A0You would only need to understand the amount of
 >>>>> brokenness of -P to see if you need to use lstat(). =A0I think -P is =
 so
 >>>>> broken that mtree on symlinks doesn't work at all and not using lstat=
 ()
 >>>>> would be safest.
 >>>>
 >>>> Hmmm... so I take it that this is actually the first step in many to
 >>>> fixing this underlying problem? I suppose I should be opening bugs for
 >>>> all of the itemized issues that you see in mtree(8) so someone can
 >>>> submit patches to fix the utility?
 >>>>
 >>>>> The patch has some style bugs.
 >>>>
 >>>> Please expound on this -- I want to improve my style (without having
 >>>> to rewrite the entire program of course) -- so that it conforms more
 >>>> to the projects overall style rules; of course there are some cases
 >>>> where I can't readily do that (like pkg_install -- ugh), but I'll do
 >>>> my best to make sure that the rules are withheld.
 >>>
 >>> s/withheld/held/
 >>>
 >>> I guess the problem was the fact that I didn't use 8-space tabs for
 >>> first-level tabs? Hard tabs are fine, correct?
 >>
 >> =A0 =A0Ah, the braces for the single line conditional. Yes, I see what
 >> you mean now (fixed).
 >> =A0 =A0Also, I see what you mean about -P being broken; mtree(8) uses
 >> chmod instead of lchmod, chown instead of lchown, etc. This definitely
 >> needs fixing and I'll assign separate PRs for it.
 >
 > Sorry -- forgot the patch.
 
 A properly style(9)zed patch.
 Thanks,
 -Garrett
 
 --005045016ba0d819d70485fbe4b3
 Content-Type: text/plain; charset=US-ASCII; name="bin.144411.diff.txt"
 Content-Disposition: attachment; filename="bin.144411.diff.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g8woe5t61
 
 SW5kZXg6IHVzci5zYmluL210cmVlL2V4Y2x1ZGVzLmMKPT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gdXNyLnNiaW4v
 bXRyZWUvZXhjbHVkZXMuYwkocmV2aXNpb24gMjA3NzQwKQorKysgdXNyLnNiaW4vbXRyZWUvZXhj
 bHVkZXMuYwkod29ya2luZyBjb3B5KQpAQCAtMzAsOSArMzAsMTAgQEAKICNpbmNsdWRlIDxzeXMv
 Y2RlZnMuaD4KIF9fRkJTRElEKCIkRnJlZUJTRCQiKTsKIAorI2luY2x1ZGUgPHN5cy9xdWV1ZS5o
 PgorI2luY2x1ZGUgPHN5cy9zdGF0Lmg+CisjaW5jbHVkZSA8c3lzL3RpbWUuaD4JCS8qIFhYWCBm
 b3IgbXRyZWUuaCAqLwogI2luY2x1ZGUgPHN5cy90eXBlcy5oPgotI2luY2x1ZGUgPHN5cy90aW1l
 Lmg+CQkvKiBYWFggZm9yIG10cmVlLmggKi8KLSNpbmNsdWRlIDxzeXMvcXVldWUuaD4KIAogI2lu
 Y2x1ZGUgPGVyci5oPgogI2luY2x1ZGUgPGZubWF0Y2guaD4KQEAgLTYzLDEzICs2NCwyOSBAQAog
 dm9pZAogcmVhZF9leGNsdWRlc19maWxlKGNvbnN0IGNoYXIgKm5hbWUpCiB7CisJc3RydWN0IGV4
 Y2x1ZGUgKmU7CisJc3RydWN0IHN0YXQgZXhjbHVkZV9zdGF0OwogCUZJTEUgKmZwOwogCWNoYXIg
 KmxpbmUsICpzdHI7Ci0Jc3RydWN0IGV4Y2x1ZGUgKmU7CiAJc2l6ZV90IGxlbjsKIAorCS8qCisJ
 ICogTGV0J3MgcmVzb2x2ZSB0aGUgbmFtZSB2aWEgc3RhdCgyKSBzbyBzeW1saW5rcyB0byBmaWxl
 cyBkb24ndCBmYWlsCisJICogdGhlIFNfSVNSRUcgY2hlY2sgYmVsb3cuCisJICovCisJaWYgKHN0
 YXQobmFtZSwgJmV4Y2x1ZGVfc3RhdCkgIT0gMCkKKwkJZXJyKEVYSVRfRkFJTFVSRSwgIiVzIiwg
 bmFtZSk7CisJLyogRG9uJ3QgbGV0IGNlcnRhaW4gZmlsZXMgbGlrZSBkaXJlY3RvcmllcywgZmlm
 b3MsIGV0YyBwYXNzLiAqLworCWlmICghU19JU1JFRyhleGNsdWRlX3N0YXQuc3RfbW9kZSkpIHsK
 KwkJLyoKKwkJICogV2Ugb25seSBhY2NlcHQgZmlsZXMgdGhhdCBhcmUgcmVndWxhciBmaWxlczsg
 YWxsIG90aGVyIGZpbGUKKwkJICogdHlwZXMgYXJlIHJlamVjdGVkLgorCQkgKi8KKwkJZXJyeChF
 WElUX0ZBSUxVUkUsICIlczogaW52YWxpZCBleGNsdWRlIGZpbGUiLCBuYW1lKTsKKwl9CisKIAlm
 cCA9IGZvcGVuKG5hbWUsICJyIik7Ci0JaWYgKGZwID09IDApCisJaWYgKGZwID09IE5VTEwpCiAJ
 CWVycigxLCAiJXMiLCBuYW1lKTsKIAogCXdoaWxlICgobGluZSA9IGZnZXRsbihmcCwgJmxlbikp
 ICE9IDApIHsK
 --005045016ba0d819d70485fbe4b3--

From: Garrett Cooper <yaneurabeya@gmail.com>
To: bug-followup <bug-followup@freebsd.org>
Cc: Bruce Evans <brde@optusnet.com.au>
Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular files for -X
Date: Wed, 13 Oct 2010 00:18:06 -0700

 --001636c933da11631d04927a65d8
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
     Forwarding the feedback received so the information gets captured in th=
 e PR.
 Thanks for the help with the review Bruce!
 -Garrett
 
 ---------- Forwarded message ----------
 From: Bruce Evans <brde@optusnet.com.au>
 Date: Tue, Oct 12, 2010 at 9:02 PM
 Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular
 files for -X
 To: Garrett Cooper <yaneurabeya@gmail.com>
 Cc: Bruce Evans <brde@optusnet.com.au>, freebsd-bugs@freebsd.org
 
 
 On Sun, 10 Oct 2010, Garrett Cooper wrote:
 
 > ...
 > =A0 I've been sitting on this PR for a while and I'd like to wrap it
 > up and move on, if that's ok. Here's a patch with a more suitable
 > comment above the stat(2) call.
 
 % Index: usr.sbin/mtree/excludes.c
 % =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 % --- usr.sbin/mtree/excludes.c (revision 213667)
 % +++ usr.sbin/mtree/excludes.c (working copy)
 % @@ -30,9 +30,10 @@
 % =A0#include <sys/cdefs.h>
 % =A0__FBSDID("$FreeBSD$");
 % % +#include <sys/queue.h>
 % +#include <sys/stat.h>
 % +#include <sys/time.h> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* XXX for mtree.h =
 */
 % =A0#include <sys/types.h>
 % -#include <sys/time.h> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* XXX for mtree.h =
 */
 % -#include <sys/queue.h>
 % % =A0#include <err.h>
 % =A0#include <fnmatch.h>
 % @@ -63,11 +64,22 @@
 % =A0void
 % =A0read_excludes_file(const char *name)
 % =A0{
 % + =A0 =A0 struct stat exclude_stat;
 % + =A0 =A0 struct exclude *e;
 % =A0 =A0 =A0 FILE *fp;
 % =A0 =A0 =A0 char *line, *str;
 % - =A0 =A0 struct exclude *e;
 % =A0 =A0 =A0 size_t len;
 % % + =A0 /* % + =A0 * Make sure that the path we're dealing with points
 to a regular file,
 % + =A0 =A0 =A0* because the exclude list should be a regular file, not a d=
 irectory,
 % + =A0 =A0 =A0* etc.
 % + =A0 =A0 =A0*/
 % + =A0 =A0 if (stat(name, &exclude_stat) !=3D 0)
 % + =A0 =A0 =A0 =A0 =A0 =A0 err(EXIT_FAILURE, "stat: %s", name);
 % + =A0 =A0 if (!S_ISREG(exclude_stat.st_mode))
 % + =A0 =A0 =A0 =A0 =A0 =A0 errx(EXIT_FAILURE, "invalid exclude file: %s", =
 name);
 % +
 % =A0 =A0 =A0 fp =3D fopen(name, "r");
 % =A0 =A0 =A0 if (fp =3D=3D 0)
 % =A0 =A0 =A0 =A0 =A0 =A0 =A0 err(1, "%s", name);
 
 I like the main part of the patch.
 
 The reordering of the includes may be premature or incomplete. =A0Old
 sources include <sys/types.h> first since it was a prerequisite for
 all POSIX headers, and most FreeBSD man pages and style(9) still say
 to do this although POSIX dropped this requirement in 2001 or earlier
 and FreeBSD mostly removed this requirement in ~2002-2003. =A0So now,
 the include of <sys/types.h> might not be needed at all, but it is
 hard to tell since there is so much pollution in other headers. =A0I
 would keep the include of <sys/types.h> first if it is kept.
 
 Bruce
 
 --001636c933da11631d04927a65d8
 Content-Type: text/plain; charset=US-ASCII; name="bin.144411.diff.txt"
 Content-Disposition: attachment; filename="bin.144411.diff.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_gf7v7you0
 
 SW5kZXg6IHVzci5zYmluL210cmVlL2V4Y2x1ZGVzLmMKPT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gdXNyLnNiaW4v
 bXRyZWUvZXhjbHVkZXMuYwkocmV2aXNpb24gMjEzNjY3KQorKysgdXNyLnNiaW4vbXRyZWUvZXhj
 bHVkZXMuYwkod29ya2luZyBjb3B5KQpAQCAtMzAsOSArMzAsMTAgQEAKICNpbmNsdWRlIDxzeXMv
 Y2RlZnMuaD4KIF9fRkJTRElEKCIkRnJlZUJTRCQiKTsKIAorI2luY2x1ZGUgPHN5cy9xdWV1ZS5o
 PgorI2luY2x1ZGUgPHN5cy9zdGF0Lmg+CisjaW5jbHVkZSA8c3lzL3RpbWUuaD4JCS8qIFhYWCBm
 b3IgbXRyZWUuaCAqLwogI2luY2x1ZGUgPHN5cy90eXBlcy5oPgotI2luY2x1ZGUgPHN5cy90aW1l
 Lmg+CQkvKiBYWFggZm9yIG10cmVlLmggKi8KLSNpbmNsdWRlIDxzeXMvcXVldWUuaD4KIAogI2lu
 Y2x1ZGUgPGVyci5oPgogI2luY2x1ZGUgPGZubWF0Y2guaD4KQEAgLTYzLDExICs2NCwyMiBAQAog
 dm9pZAogcmVhZF9leGNsdWRlc19maWxlKGNvbnN0IGNoYXIgKm5hbWUpCiB7CisJc3RydWN0IHN0
 YXQgZXhjbHVkZV9zdGF0OworCXN0cnVjdCBleGNsdWRlICplOwogCUZJTEUgKmZwOwogCWNoYXIg
 KmxpbmUsICpzdHI7Ci0Jc3RydWN0IGV4Y2x1ZGUgKmU7CiAJc2l6ZV90IGxlbjsKIAorCS8qIAor
 CSAqIE1ha2Ugc3VyZSB0aGF0IHRoZSBwYXRoIHdlJ3JlIGRlYWxpbmcgd2l0aCBwb2ludHMgdG8g
 YSByZWd1bGFyIGZpbGUsCisJICogYmVjYXVzZSB0aGUgZXhjbHVkZSBsaXN0IHNob3VsZCBiZSBh
 IHJlZ3VsYXIgZmlsZSwgbm90IGEgZGlyZWN0b3J5LAorCSAqIGV0Yy4KKwkgKi8KKwlpZiAoc3Rh
 dChuYW1lLCAmZXhjbHVkZV9zdGF0KSAhPSAwKQorCQllcnIoRVhJVF9GQUlMVVJFLCAic3RhdDog
 JXMiLCBuYW1lKTsKKwlpZiAoIVNfSVNSRUcoZXhjbHVkZV9zdGF0LnN0X21vZGUpKQorCQllcnJ4
 KEVYSVRfRkFJTFVSRSwgImludmFsaWQgZXhjbHVkZSBmaWxlOiAlcyIsIG5hbWUpOworCiAJZnAg
 PSBmb3BlbihuYW1lLCAiciIpOwogCWlmIChmcCA9PSAwKQogCQllcnIoMSwgIiVzIiwgbmFtZSk7
 Cg==
 --001636c933da11631d04927a65d8--

From: Garrett Cooper <yaneurabeya@gmail.com>
To: bug-followup@FreeBSD.org, gcooper@FreeBSD.org
Cc:  
Subject: Re: bin/144411: [patch] mtree(8) doesn't reject non-regular files for -X
Date: Fri, 15 Oct 2010 23:59:13 -0700

     I was completely misdiagnosing the problem as mtree is only
 hanging because it's waiting for input on stdin as the example I
 provided doesn't use -c. Please close this bug.
 Sorry for the noise,
 -Garrett
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Sat Oct 16 10:06:05 UTC 2010 
State-Changed-Why:  
Closed at submitter's request. 

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