bin/60524: mtree tumbles on files begining with hashmark(#)

Hiroharu Tamaru tamaru at myn.rcast.u-tokyo.ac.jp
Sun Apr 25 08:18:54 PDT 2004


Thank you for looking into this Kris.

At Sat, 24 Apr 2004 00:49:25 -0700 (PDT),
Kris Kennaway wrote:
> 
> Synopsis: mtree tumbles on files begining with hashmark(#)
> 
> State-Changed-From-To: patched->closed
> State-Changed-By: kris
> State-Changed-When: Sat Apr 24 00:49:05 PDT 2004
> State-Changed-Why: 
> MFC will not be performed since the change breaks compatibility with older mtree files.
> 
> http://www.freebsd.org/cgi/query-pr.cgi?pr=60524

Since the actual fix committed to -current is a more robust
one than that I proposed, I believe the changes are fully
backward compatible.  It uses octal escapes (such as \043
for #) that had been supported by mtree all the time.  That
is to say:

An old mtree file that doesn't have any special chars is
readable by new mtree program. 

An old mtree file that have special chars like # is broken
anyways and is unreadable by both old and new mtree program

A new mtree file that doesn't have any special chars is
readable by old mtree program.

A new mtree file that have special chars is readable by old
mtree program.

That said, are there other compatibility issues that I
couldn't come up with?  Please point me to the archives if
there was an discussion.

Thank you.


I'll attach a patch against -stable as of today for your
reference.  It MFC's revision 1.32 of create.c, revisions
1.11, 1.12 and 1.13 of vis.c, and revisions 1.19 thru 1.23
of vis.3.

You could also consider MFC'ing 1.9 and 1.10 for vis.c.

--- usr.sbin/mtree/create.c.orig	Sun Apr 25 23:36:22 2004
+++ usr.sbin/mtree/create.c	Sun Apr 25 23:37:52 2004
@@ -159,7 +159,7 @@
 	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);
+	strvis(escaped_name, p->fts_name, VIS_WHITE | VIS_OCTAL | VIS_GLOB);
 
 	if (iflag || S_ISDIR(p->fts_statp->st_mode))
 		offset = printf("%*s%s", indent, "", escaped_name);
--- lib/libc/gen/vis.c.orig	Sun Apr 25 23:36:06 2004
+++ lib/libc/gen/vis.c	Sun Apr 25 23:38:03 2004
@@ -71,7 +71,10 @@
 		}
 	}
 
-	if (isgraph(c) ||
+	if ((flag & VIS_GLOB) &&
+	    (c == '*' || c == '?' || c == '[' || c == '#'))
+		;
+	else if (isgraph(c) ||
 	   ((flag & VIS_SP) == 0 && c == ' ') ||
 	   ((flag & VIS_TAB) == 0 && c == '\t') ||
 	   ((flag & VIS_NL) == 0 && c == '\n') ||
@@ -131,7 +134,7 @@
 			goto done;
 		}
 	}
-	if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
+	if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
 		*dst++ = '\\';
 		*dst++ = ((u_char)c >> 6 & 07) + '0';
 		*dst++ = ((u_char)c >> 3 & 07) + '0';
@@ -163,7 +166,7 @@
  * strvis, strvisx - visually encode characters from src into dst
  *
  *	Dst must be 4 times the size of src to account for possible
- *	expansion.  The length of dst, not including the trailing NULL,
+ *	expansion.  The length of dst, not including the trailing NUL,
  *	is returned.
  *
  *	Strvisx encodes exactly len bytes from src into dst.
--- lib/libc/gen/vis.3.orig	Mon Apr 26 00:11:59 2004
+++ lib/libc/gen/vis.3	Mon Apr 26 00:11:43 2004
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     From: @(#)vis.3	8.1 (Berkeley) 6/9/93
 .\" $FreeBSD: src/lib/libc/gen/vis.3,v 1.8.2.6 2001/12/14 18:33:51 ru Exp $
 .\"
-.Dd July 25, 1996
+.Dd March 21, 2004
 .Dt VIS 3
 .Os
 .Sh NAME
@@ -67,7 +67,9 @@
 encoding a set of characters into a buffer, the size of the buffer should
 be four times the number of characters encoded, plus one for the trailing
 .Dv NUL .
-The flag parameter is used for altering the default range of
+The
+.Fa flag
+argument is used for altering the default range of
 characters considered for encoding and for altering the visual
 representation.
 The additional character,
@@ -135,6 +137,9 @@
 The following flags
 alter this:
 .Bl -tag -width VIS_WHITEX
+.It Dv VIS_GLOB
+Also encode magic characters ('*', '?', '[' and '#') recognized by
+.Xr glob 3
 .It Dv VIS_SP
 Also encode space.
 .It Dv VIS_TAB
@@ -227,7 +232,9 @@
 .Li \e0 Tn  - NUL No (000)
 .Ed
 .Pp
-When using this format, the nextc parameter is looked at to determine
+When using this format, the
+.Fa nextc
+argument is looked at to determine
 if a
 .Dv NUL
 character can be encoded as
@@ -243,13 +250,13 @@
 The form is
 .Ql %dd
 where
-.Em d
+.Ar d
 represents a hexadecimal digit.
 .It Dv VIS_OCTAL
 Use a three digit octal sequence.  The form is
 .Ql \eddd
 where
-.Em d
+.Ar d
 represents an octal digit.
 .El
 .Pp
@@ -275,3 +282,9 @@
 .Sh HISTORY
 These functions first appeared in
 .Bx 4.4 .
+.Sh BUGS
+The
+.Nm
+family of functions do not recognize multibyte characters, and thus
+may consider them to be non-printable when they are in fact printable
+(and vice versa.)


More information about the freebsd-bugs mailing list