NetBSD Problem Report #56733

From www@netbsd.org  Mon Feb 28 13:30:26 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 3E4491A9239
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 28 Feb 2022 13:30:26 +0000 (UTC)
Message-Id: <20220228133024.BD9881A923A@mollari.NetBSD.org>
Date: Mon, 28 Feb 2022 13:30:24 +0000 (UTC)
From: jgoerzen@complete.org
Reply-To: jgoerzen@complete.org
To: gnats-bugs@NetBSD.org
Subject: mtree bug processing filenames containing asterisks
X-Send-Pr-Version: www-1.0

>Number:         56733
>Category:       pkg
>Synopsis:       mtree bug processing filenames containing asterisks
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 28 13:35:00 +0000 2022
>Last-Modified:  Thu Apr 21 03:00:02 +0000 2022
>Originator:     John Goerzen
>Release:        Looks to date back 12 years or so
>Organization:
>Environment:
>Description:
Let's say I have a directory containing these files, one of which contains an asterisk:

file*
file2.txt
file.txt
file3.txt

Further assume they are different sizes and have different content.

If, in the output from mtree -c, file* is emitted before the others, the later mtree verify will apparently match all four files using the rule file* and emit errors on the other three.  I observed this in the wild.

A workaround is to manually edit the emitted mtree data and move file* to be after the other non-wildcard files; then it will properly verify.

Additionally, the support for wildcards in the mtree format is not documented that I can see, and probably should be.  Or perhaps it should be removed, since AFAICT, no tools are generating mtree files intentionally using this feature.
>How-To-Repeat:
See above
>Fix:
This may be related to the call to fnmatch in http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/pkgtools/mtree/files/verify.c?rev=1.6&content-type=text/x-cvsweb-markup .

Probably, either:

1) wildcard support in the mtree format should be removed,

or 2) the generation code needs to escape fnmatch glob characters in its output, and this should all be documented.

>Audit-Trail:
From: Joerg Sonnenberger <joerg@bec.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/56733: mtree bug processing filenames containing asterisks
Date: Tue, 1 Mar 2022 13:36:06 +0100

 Am Mon, Feb 28, 2022 at 01:35:00PM +0000 schrieb jgoerzen@complete.org:
 > Additionally, the support for wildcards in the mtree format is not documented that I can see, and probably should be.  Or perhaps it should be removed, since AFAICT, no tools are generating mtree files intentionally using this feature.

 It is documented. But mtree -c should quote them, at least if the mtree
 variant supports quoting.

 Joerg

From: John Goerzen <jgoerzen@complete.org>
To: gnats-bugs@netbsd.org
Cc: pkg-manager@netbsd.org, gnats-admin@netbsd.org, pkgsrc-bugs@netbsd.org
Subject: Re: pkg/56733: mtree bug processing filenames containing asterisks
Date: Tue, 01 Mar 2022 07:48:47 -0600

 On Tue, Mar 01 2022, Joerg Sonnenberger wrote:

 >  Am Mon, Feb 28, 2022 at 01:35:00PM +0000 schrieb jgoerzen@complete.org:
 >  > Additionally, the support for wildcards in the mtree format is not documented that I can see, and probably should be.  Or perhaps it should be removed, since AFAICT, no tools are generating mtree files intentionally using this feature.
 >
 >  It is documented. But mtree -c should quote them, at least if the mtree
 >  variant supports quoting.

 Hi Joerg,

 I was creating the specification with mtree -c.  I wasn't using -C.  The
 command I used was:

 mtree -c -K "uid,gid,sha256" -p pathname

 I can confirm that * was definitely not quoted in the output.  Other
 characters, such as spaces, were.

 - John

From: David Holland <dholland-pbugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/56733: mtree bug processing filenames containing asterisks
Date: Thu, 21 Apr 2022 02:58:27 +0000

 Not sent to gnats.
 (All bug database traffic should be sent to gnats-bugs@. This usually
 doesn't happen automatically if you reply to yourself.)

    ------

 From: John Goerzen <jgoerzen@complete.org>
 To: pkg-manager@netbsd.org, gnats-admin@netbsd.org, pkgsrc-bugs@netbsd.org, jgoerzen@complete.org
 Subject: Re: pkg/56733: mtree bug processing filenames containing asterisks
 Date: Tue, 01 Mar 2022 09:47:31 -0600

 FWIW, I just realized that there are two different mtree trees in
 NetBSD; one in pkgsrc, and one in src/usr.sbin.

 I have been using the one from pkgsrc, and was asked to submit here.
 The trees are related but divergent.

 This patch fixes the issue for me with the pkgsrc tree:

 --- verify.c.orig       2018-08-22 15:48:38.000000000 -0500
 +++ verify.c    2022-03-01 09:45:04.854574448 -0600
 @@ -142,9 +142,7 @@
                 if (specdepth != p->fts_level)
                         goto extra;
                 for (ep = level; ep; ep = ep->next)
 -                       if ((ep->flags & F_MAGIC &&
 -                           !fnmatch(ep->name, p->fts_name, FNM_PATHNAME)) ||
 -                           !strcmp(ep->name, p->fts_name)) {
 +                       if (!strcmp(ep->name, p->fts_name)) {
                                 ep->flags |= F_VISIT;
                                 if (compare(ep, p))
                                         rval = MISMATCHEXIT;

 - John


 From: John Goerzen <jgoerzen@complete.org>
 To: pkg-manager@netbsd.org, gnats-admin@netbsd.org, pkgsrc-bugs@netbsd.org, jgoerzen@complete.org
 Subject: Re: pkg/56733: mtree bug processing filenames containing asterisks
 Date: Tue, 01 Mar 2022 09:57:03 -0600

 I should add -- from what I can see, the bug exists in the same way in
 the usr.sbin tree and this fix ought to apply there as well.

 John

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.