Date: Mon, 11 Jan 1999 04:44:45 -0800 (PST) From: "Eugene M. Kim" <astralblue@usa.net> To: freebsd-bugs@FreeBSD.ORG Cc: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>, Joseph Koshy <jkoshy@FreeBSD.ORG> Subject: Re: bin/3246: mtree -c should escape whitespace and special characters Message-ID: <Pine.BSF.4.02A.9901110436160.1368-100000@gw1.pl.cp> In-Reply-To: <199901061541.KAA22479@khavrinen.lcs.mit.edu>
index | next in thread | previous in thread | raw e-mail
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 <stdio.h>
#include <time.h>
#include <unistd.h>
+ #include <vis.h>
#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 <pwd.h>
#include <stdio.h>
#include <unistd.h>
+ #include <vis.h>
#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 <astralblue@usa.net>
"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
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.02A.9901110436160.1368-100000>
