From nobody@FreeBSD.org  Fri Feb 22 18:43:02 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 7E5C337B419
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Feb 2002 18:43:01 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g1N2h1J63548;
	Fri, 22 Feb 2002 18:43:01 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200202230243.g1N2h1J63548@freefall.freebsd.org>
Date: Fri, 22 Feb 2002 18:43:01 -0800 (PST)
From: Oyvind Idland <oyvind@punkass.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: mtree - strange behaviour on some filenames
X-Send-Pr-Version: www-1.0

>Number:         35226
>Category:       bin
>Synopsis:       mtree - strange behaviour on some filenames
>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:   Fri Feb 22 18:50:01 PST 2002
>Closed-Date:    Tue Aug 13 10:14:14 PDT 2002
>Last-Modified:  Tue Aug 13 10:55:26 PDT 2002
>Originator:     Oyvind Idland
>Release:        4.5-RELEASE
>Organization:
>Environment:
FreeBSD cow 4.5-RELEASE FreeBSD 4.5-RELEASE #0: Sun Feb  3 01:26:06 GMT 2002
>Description:
mtree seems to have problems with some filenames. I got some files in /usr/local/bin, seems like scripts installed via the PHP-package.
examples:
#INST@90698#
#INST@90720#
#INST@90742#

when i run mtree against a spec, i get:
#INST@90698# extra
#INST@90720# extra
#INST@90742# extra
....<more>.....
allthough the files are listed in my spec:
    #INST@90698#    size=700 time=1014200710.0
    #INST@90720#    size=528 time=1014200710.0
    #INST@90742#    size=10018 time=1014200710.0

>How-To-Repeat:
i just ran:
mtree -c -i -p /usr/local/bin >foo.mtree
and oposite
mtree -f foo.mtree -p /usr/local/bin

>Fix:
     
>Release-Note:
>Audit-Trail:

From: "Andrew L. Neporada" <andr@dgap.mipt.ru>
To: bug-followup@freebsd.org
Cc: oyvind@punkass.com
Subject: [PATCH] Re: bin/35226 mtree strange behaviour on some filenames
Date: Sun, 17 Mar 2002 02:46:32 +0300 (MSK)

 Bug happens when the first symbol of filename is '#', because '#'
 is the comment marker also.
 
 Apply following patch (patch done against -current):
 
 Index: create.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/mtree/create.c,v
 retrieving revision 1.22
 diff -u -r1.22 create.c
 --- create.c	5 Jul 2001 07:52:56 -0000	1.22
 +++ create.c	16 Mar 2002 21:59:58 -0000
 @@ -159,7 +159,12 @@
  	escaped_name = calloc(1, p->fts_namelen * 4  +  1);
  	if (escaped_name == NULL)
  		errx(1, "statf(): calloc() failed");
 -	strvis(escaped_name, p->fts_name, VIS_WHITE | VIS_OCTAL);
 +	len = strvis(escaped_name, p->fts_name, VIS_WHITE | VIS_OCTAL);
 +	if (escaped_name[0] == '#') {
 +		for (val = len; val; val--)
 +			escaped_name[val] = escaped_name[val-1];
 +		escaped_name[0] = '\\';
 +	}
 
  	if (iflag || S_ISDIR(p->fts_statp->st_mode))
  		offset = printf("%*s%s", indent, "", escaped_name);
 Index: spec.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/mtree/spec.c,v
 retrieving revision 1.14
 diff -u -r1.14 spec.c
 --- spec.c	17 Jun 2000 14:19:33 -0000	1.14
 +++ spec.c	16 Mar 2002 22:24:52 -0000
 @@ -65,6 +65,7 @@
  	register char *p;
  	NODE ginfo, *root;
  	int c_cur, c_next;
 +	u_long i, len;
  	char buf[2048];
 
  	centry = last = root = NULL;
 @@ -147,6 +148,11 @@
  #define	MAGIC	"?*["
  		if (strpbrk(p, MAGIC))
  			centry->flags |= F_MAGIC;
 +		if (p[0] == '\\' && p[1] == '#') {
 +			len = strlen(p);
 +			for(i = 0; i < len; i++)
 +				p[i] = p[i + 1];
 +		}
  		if (strunvis(centry->name, p) == -1) {
  			warnx("filename %s is ill-encoded and literally used",
  			    p);
 
State-Changed-From-To: open->closed 
State-Changed-By: schweikh 
State-Changed-When: Tue Aug 13 10:13:35 PDT 2002 
State-Changed-Why:  
Please see the mtree meta PR 41583. 

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