From nicolas@narr.dyn.dhs.org  Fri Mar  1 06:33:51 2002
Return-Path: <nicolas@narr.dyn.dhs.org>
Received: from mailout03.sul.t-online.com (mailout03.sul.t-online.com [194.25.134.81])
	by hub.freebsd.org (Postfix) with ESMTP id B599737B417
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  1 Mar 2002 06:33:49 -0800 (PST)
Received: from fwd08.sul.t-online.de 
	by mailout03.sul.t-online.com with smtp 
	id 16go6W-0007du-03; Fri, 01 Mar 2002 15:33:48 +0100
Received: from pc5.abc (520067998749-0001@[217.233.125.95]) by fmrl08.sul.t-online.com
	with esmtp id 16go6O-0AVyxUC; Fri, 1 Mar 2002 15:33:40 +0100
Received: (from nicolas@localhost)
	by pc5.abc (8.11.6/8.11.6) id g21EXdB10566;
	Fri, 1 Mar 2002 15:33:39 +0100 (CET)
	(envelope-from nicolas)
Message-Id: <200203011433.g21EXdB10566@pc5.abc>
Date: Fri, 1 Mar 2002 15:33:39 +0100 (CET)
From: Nicolas Rachinsky <list@rachinsky.de>
Reply-To: Nicolas Rachinsky <list@rachinsky.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: mtree can't handle symlinks referencing files which names contain spaces
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         35454
>Category:       bin
>Synopsis:       mtree can't handle symlinks referencing files which names contain spaces
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 01 06:40:01 PST 2002
>Closed-Date:    Tue Aug 13 10:14:40 PDT 2002
>Last-Modified:  Tue Aug 13 10:56:28 PDT 2002
>Originator:     Nicolas Rachinsky
>Release:        FreeBSD 4.5-RELEASE i386
>Organization:
>Environment:
System: FreeBSD pc5.abc 4.5-RELEASE FreeBSD 4.5-RELEASE #2: Wed Feb 27 12:29:06 CET 2002 nicolas@pc5.abc:/usr/src/sys/compile/NR i386


	
>Description:

mtree cannot handle symlinks pointing to files with spaces in their names

>How-To-Repeat:

Script started on Wed Feb 20 00:22:11 2002
nicolas@pc5 ~/tmp> touch a\ a
nicolas@pc5 ~/tmp> ln -s a\ a t
nicolas@pc5 ~/tmp> mtree -c >list
nicolas@pc5 ~/tmp> mtree <list
mtree: line 11: unknown keyword a
nicolas@pc5 ~/tmp> cat list
#          user: nicolas
#       machine: pc5.abc
#          tree: /data/home/nicolas/tmp
#          date: Wed Feb 20 00:22:37 2002

# .
/set type=file uid=1003 gid=1001 mode=0644 nlink=1 flags=none
.               type=dir mode=0755 nlink=2 size=512 time=1014160957.0
    a\040a      size=0 time=1014160937.0
    list        size=0 time=1014160957.0
    t           type=link mode=0755 size=3 time=1014160945.0 link=a a
    typescript  size=43 time=1014160947.0
..

nicolas@pc5 ~/tmp> ^D

Script done on Wed Feb 20 00:22:50 2002


>Fix:

escape the whitespace in the link= part (AFAIK that's not possible in the
moment)


>Release-Note:
>Audit-Trail:

From: Nicolas Rachinsky <list@rachinsky.de>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/35454: mtree can't handle symlinks referencing files which names contain spaces
Date: Fri, 8 Mar 2002 23:47:04 +0100

 I've just created this patch which seems to solve the problem:
 
 
 Index: create.c
 ===================================================================
 RCS file: /usr/cvs-freebsd/src/usr.sbin/mtree/create.c,v
 retrieving revision 1.18.2.3
 diff -u -r1.18.2.3 create.c
 --- create.c	12 Jan 2001 19:17:18 -0000	1.18.2.3
 +++ create.c	8 Mar 2002 22:38:18 -0000
 @@ -154,7 +154,7 @@
  	u_long len, val;
  	int fd, offset;
  	char *fflags;
 -	char *escaped_name;
 +	char *escaped_name,*s;
  
  	escaped_name = calloc(1, p->fts_namelen * 4  +  1);
  	if (escaped_name == NULL)
 @@ -256,7 +256,18 @@
  #endif /* RMD160 */
  	if (keys & F_SLINK &&
  	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
 -		output(indent, &offset, "link=%s", rlink(p->fts_accpath));
 +	{
 +		s=strdup(rlink(p->fts_accpath));
 +		if(!s)
 +			errx(1, "statf(): strdup() failed");
 +		escaped_name = calloc(1, strlen(s) * 4  +  1);
 +		if (escaped_name == NULL)
 +			errx(1, "statf(): calloc() failed");
 +		strvis(escaped_name, s, VIS_WHITE | VIS_OCTAL);
 +		output(indent, &offset, "link=%s", escaped_name);
 +		free(escaped_name);
 +		free(s);
 +	}
  	if (keys & F_FLAGS && p->fts_statp->st_flags != flags) {
  		fflags = flags_to_string(p->fts_statp->st_flags);
  		output(indent, &offset, "flags=%s", fflags);
 Index: spec.c
 ===================================================================
 RCS file: /usr/cvs-freebsd/src/usr.sbin/mtree/spec.c,v
 retrieving revision 1.13.2.1
 diff -u -r1.13.2.1 spec.c
 --- spec.c	28 Jun 2000 02:33:17 -0000	1.13.2.1
 +++ spec.c	8 Mar 2002 22:40:21 -0000
 @@ -181,6 +181,7 @@
  	mode_t *m;
  	int value;
  	char *ep;
 +	char *escaped_string;
  
  	for (; (kw = strtok(t, "= \t\n")); t = NULL) {
  		ip->flags |= type = parsekey(kw, &value);
 @@ -250,8 +251,16 @@
  				lineno, val);
  			break;
  		case F_SLINK:
 -			if ((ip->slink = strdup(val)) == NULL)
 +			if ((escaped_string = strdup(val)) == NULL)
  				errx(1, "strdup");
 +			if((ip->slink=calloc(1, strlen(escaped_string)  +  1)) == NULL)
 +				errx(1, "set(): calloc() failed");
 +			if (strunvis(ip->slink, escaped_string) == -1) {
 +				warnx("filename %s is ill-encoded and literally used",
 +				      escaped_string);
 +				strcpy(ip->slink, escaped_string); 
 +			}
 +			free(escaped_string);
  			break;
  		case F_TIME:
  			ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10);
State-Changed-From-To: open->closed 
State-Changed-By: schweikh 
State-Changed-When: Tue Aug 13 10:14:23 PDT 2002 
State-Changed-Why:  
Please see the mtree meta PR 41583. 

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