NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/59838: mtree: Fix parsing 'K', 'k', with 'R' flags
>Number: 59838
>Category: bin
>Synopsis: mtree: Fix parsing 'K', 'k', with 'R' flags
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Dec 15 05:20:00 +0000 2025
>Originator: Jose Luis Duran
>Release: trunk
>Organization:
FreeBSD
>Environment:
>Description:
It was reported on
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219467
that an mtree command with -k and -R flags do not work as expected.
In mtree, the -k flag uses the type keyword plus the specified keywords. If the type keyword is not desired, it can be suppressed with -R type.
But issuing:
# mtree -cn -R type -k flags -p /usr/bin/ -x | grep type=
Doesn't seem to work as expected.
>How-To-Repeat:
# mtree -cn -R type -k flags -p /usr/bin/ -x | grep type=
>Fix:
A very straightforward solution is offered:
Move the parsing of the keywords for the 'K', 'k', and 'R' flags outside the getopt loop, so that the order of the flags does not matter.
Also, check for the presence of the F_TYPE flag before printing the type keyword.
---
contrib/mtree/create.c | 3 ++-
contrib/mtree/mtree.c | 30 +++++++++++++++++++++---------
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/contrib/mtree/create.c b/contrib/mtree/create.c
index e23004851f39..245b9efa1c35 100644
--- a/contrib/mtree/create.c
+++ b/contrib/mtree/create.c
@@ -236,7 +236,8 @@ statf(FILE *fp, int indent, FTSENT *p)
offset += fprintf(fp, "%*s",
(INDENTNAMELEN + indent) - offset, "");
- if (!S_ISREG(p->fts_statp->st_mode) && (flavor == F_NETBSD6 || !dflag))
+ if (keys & F_TYPE && !S_ISREG(p->fts_statp->st_mode) &&
+ (flavor == F_NETBSD6 || !dflag))
output(fp, indent, &offset, "type=%s",
inotype(p->fts_statp->st_mode));
if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) {
diff --git a/contrib/mtree/mtree.c b/contrib/mtree/mtree.c
index 28f09fa32210..198db961e305 100644
--- a/contrib/mtree/mtree.c
+++ b/contrib/mtree/mtree.c
@@ -80,12 +80,14 @@ main(int argc, char **argv)
int ch, status;
unsigned int i;
int cflag, Cflag, Dflag, Uflag, wflag;
+ char *koptarg, *Koptarg, *Roptarg;
char *dir, *p;
FILE *spec1, *spec2;
setprogname(argv[0]);
cflag = Cflag = Dflag = Uflag = wflag = 0;
+ koptarg = Koptarg = Roptarg = NULL;
dir = NULL;
init_excludes();
spec1 = stdin;
@@ -150,14 +152,10 @@ main(int argc, char **argv)
break;
case 'k':
keys = F_TYPE;
- while ((p = strsep(&optarg, " \t,")) != NULL)
- if (*p != '\0')
- keys |= parsekey(p, NULL);
+ koptarg = optarg;
break;
case 'K':
- while ((p = strsep(&optarg, " \t,")) != NULL)
- if (*p != '\0')
- keys |= parsekey(p, NULL);
+ Koptarg = optarg;
break;
case 'l':
lflag = 1;
@@ -198,9 +196,7 @@ main(int argc, char **argv)
rflag++;
break;
case 'R':
- while ((p = strsep(&optarg, " \t,")) != NULL)
- if (*p != '\0')
- keys &= ~parsekey(p, NULL);
+ Roptarg = optarg;
break;
case 's':
sflag = 1;
@@ -243,6 +239,22 @@ main(int argc, char **argv)
if (argc)
usage();
+ if (koptarg != NULL) {
+ while ((p = strsep(&koptarg, " \t,")) != NULL)
+ if (*p != '\0')
+ keys |= parsekey(p, NULL);
+ }
+ if (Koptarg != NULL) {
+ while ((p = strsep(&Koptarg, " \t,")) != NULL)
+ if (*p != '\0')
+ keys |= parsekey(p, NULL);
+ }
+ if (Roptarg != NULL) {
+ while ((p = strsep(&Roptarg, " \t,")) != NULL)
+ if (*p != '\0')
+ keys &= ~parsekey(p, NULL);
+ }
+
switch (flavor) {
case F_FREEBSD9:
if (cflag && iflag) {
Home |
Main Index |
Thread Index |
Old Index