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

Hiroharu Tamaru tamaru at
Tue Dec 23 00:20:15 PST 2003

>Number:         60524
>Category:       bin
>Synopsis:       mtree tumbles on files begining with hashmark(#)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 23 00:20:10 PST 2003
>Originator:     Hiroharu Tamaru
>Release:        FreeBSD 4.9-STABLE i386
The University of Tokyo
System: FreeBSD gin 4.9-STABLE FreeBSD 4.9-STABLE #0: Fri Nov 28 15:13:39 JST 2003 MYN-P6 i386

mtree fails to handle filenames that begin with hashmark(#).
It writes the mtree file fine in -c mode, but skips the line
as a comment line in check mode and thus gives false alarm.
echo a > #a
echo b > a
echo c > a#
echo d > '\a'
echo e > 'a\'
echo f > '\#a'
echo g > b
ls -l
total 7
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 #a
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 \#a
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 \a
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 a
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 a#
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 a\
-rw-r--r--  1 tamaru  wheel  2 Dec 23 16:55 b
mtree -c -K md5digest > /tmp/test.mtree
mtree < /tmp/test.mtree
. changed
        MD5 expected 60b725f10c9c85c70d97880dfe8191b3 found 1335b892002f8dcf803\
#a extra

cat /tmp/test.mtree
# .
/set type=file uid=0 gid=0 mode=0644 nlink=1 flags=none
.               type=dir uid=10001 mode=0755 nlink=2 size=512 \
    #a          uid=10001 size=2 time=1072166144.0 \
    \\#a        uid=10001 size=2 time=1072166144.0 \
    \\a         uid=10001 size=2 time=1072166144.0 \
    a           uid=10001 size=2 time=1072166144.0 \
    a#          uid=10001 size=2 time=1072166144.0 \
    a\\         uid=10001 size=2 time=1072166144.0 \
    b           uid=10001 size=2 time=1072166144.0 \


Since backslashes are escaped correctly, I suggest that a leading hashmark
be escaped as '\#'.
Adding a backslash before # by hand in a mtree file does not solve the
problem, so I assume that both writeing and reading routines should be
Curretly, as I see it, a file named '\#a' is written in mtree file as
'\\#a', but an mtree file that reads '\#a' is also interpreted as filename
'\#a', which may or may not be a real compatibility issue.

I haven't dug into the source to come up with a patch, sorry.

More information about the freebsd-bugs mailing list