From owner-freebsd-bugs Mon Jan 11 04:45:24 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA28039 for freebsd-bugs-outgoing; Mon, 11 Jan 1999 04:45:24 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from gw1.pl.cp (redion.nttmcl.com [216.69.69.40]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id EAA28027; Mon, 11 Jan 1999 04:45:20 -0800 (PST) (envelope-from astralblue@usa.net) Received: from localhost (gene@localhost) by gw1.pl.cp (8.9.1/8.9.1) with SMTP id EAA01399; Mon, 11 Jan 1999 04:44:46 -0800 (PST) (envelope-from astralblue@usa.net) X-Authentication-Warning: gw1.pl.cp: gene owned process doing -bs Date: Mon, 11 Jan 1999 04:44:45 -0800 (PST) From: "Eugene M. Kim" X-Sender: gene@gw1.pl.cp To: freebsd-bugs@FreeBSD.ORG cc: Garrett Wollman , Joseph Koshy Subject: Re: bin/3246: mtree -c should escape whitespace and special characters In-Reply-To: <199901061541.KAA22479@khavrinen.lcs.mit.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following is a revised patch to fix the problem; please review it. Changes made: * strvis(3)/strunvis(3) used instead * style(9) conformance To Joseph Koshy, regarding calloc() size: we don't have to consider the space for trailing '\0', since name[] is already defined to have one character. We are adding only the extra space for the name itself. Cheers, Eugene --------------------------------- snip --------------------------------- diff -cr src/usr.sbin/mtree.old/create.c src/usr.sbin/mtree/create.c *** src/usr.sbin/mtree.old/create.c Mon Jan 11 00:26:54 1999 --- src/usr.sbin/mtree/create.c Mon Jan 11 02:08:08 1999 *************** *** 52,57 **** --- 52,58 ---- #include #include #include + #include #include "mtree.h" #include "extern.h" *************** *** 138,148 **** struct passwd *pw; u_long len, val; int fd, offset; if (iflag || S_ISDIR(p->fts_statp->st_mode)) ! offset = printf("%*s%s", indent, "", p->fts_name); else ! offset = printf("%*s %s", indent, "", p->fts_name); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; --- 139,157 ---- struct passwd *pw; u_long len, val; int fd, offset; + static char *escaped_name; + + escaped_name = calloc(1, p->fts_namelen * 4); + if (escaped_name == NULL) + errx(1, "statf(): calloc() failed"); + strvis(escaped_name, p->fts_name, VIS_WHITE); if (iflag || S_ISDIR(p->fts_statp->st_mode)) ! offset = printf("%*s%s", indent, "", escaped_name); else ! offset = printf("%*s %s", indent, "", escaped_name); ! ! free(escaped_name); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; diff -cr src/usr.sbin/mtree.old/spec.c src/usr.sbin/mtree/spec.c *** src/usr.sbin/mtree.old/spec.c Mon Jan 11 00:27:14 1999 --- src/usr.sbin/mtree/spec.c Mon Jan 11 02:12:32 1999 *************** *** 49,54 **** --- 49,55 ---- #include #include #include + #include #include "mtree.h" #include "extern.h" *************** *** 143,152 **** if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL) errx(1, "calloc"); *centry = ginfo; - (void)strcpy(centry->name, p); #define MAGIC "?*[" if (strpbrk(p, MAGIC)) centry->flags |= F_MAGIC; set(NULL, centry); if (!root) { --- 144,157 ---- if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL) errx(1, "calloc"); *centry = ginfo; #define MAGIC "?*[" if (strpbrk(p, MAGIC)) centry->flags |= F_MAGIC; + if (strunvis(centry->name, p) == -1) { + warnx("filename %s is ill-encoded and literally used", + p); + strcpy(centry->name, p); + } set(NULL, centry); if (!root) { --------------------------------- snip --------------------------------- -- Eugene M. Kim "Is your music unpopular? Make it popular; make music which people like, or make people who like your music." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message