diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-03-09 18:49:10 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-03-09 18:49:10 +0000 |
commit | d3a35323c0d4a2065db2b85a6170e2e9e5992bb7 (patch) | |
tree | 4098d208af6c3617e41b3b9ce7fdfb954fe20f86 | |
parent | c88c2d6e538b668a31d9e3bb01ab994c899a595b (diff) |
Escape whitespace and encode special chars with vis(3); from FreeBSD
-rw-r--r-- | usr.sbin/mtree/create.c | 17 | ||||
-rw-r--r-- | usr.sbin/mtree/spec.c | 11 |
2 files changed, 21 insertions, 7 deletions
diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c index 54c4fa4fb3d..cf410e441c5 100644 --- a/usr.sbin/mtree/create.c +++ b/usr.sbin/mtree/create.c @@ -1,5 +1,5 @@ /* $NetBSD: create.c,v 1.11 1996/09/05 09:24:19 mycroft Exp $ */ -/* $OpenBSD: create.c,v 1.15 2002/02/19 19:39:40 millert Exp $ */ +/* $OpenBSD: create.c,v 1.16 2002/03/09 18:49:09 millert Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: create.c,v 1.15 2002/02/19 19:39:40 millert Exp $"; +static const char rcsid[] = "$OpenBSD: create.c,v 1.16 2002/03/09 18:49:09 millert Exp $"; #endif #endif /* not lint */ @@ -54,6 +54,7 @@ static const char rcsid[] = "$OpenBSD: create.c,v 1.15 2002/02/19 19:39:40 mille #include <unistd.h> #include <stdio.h> #include <stdarg.h> +#include <vis.h> #include <md5.h> #include <sha1.h> #include <rmd160.h> @@ -144,11 +145,19 @@ statf(indent, p) struct passwd *pw; u_int32_t len, val; int fd, offset; + char *escaped_name; + + escaped_name = malloc(p->fts_namelen * 4 + 1); + if (escaped_name == NULL) + error("statf: %s", strerror(errno)); + strvis(escaped_name, p->fts_name, VIS_WHITE | VIS_OCTAL); if (iflag || S_ISDIR(p->fts_statp->st_mode)) - offset = printf("%*s%s", indent, "", p->fts_name); + offset = printf("%*s%s", indent, "", escaped_name); else - offset = printf("%*s %s", indent, "", p->fts_name); + offset = printf("%*s %s", indent, "", escaped_name); + + free(escaped_name); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 52217c89fc8..84a29526bc5 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -1,5 +1,5 @@ /* $NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $ */ -/* $OpenBSD: spec.c,v 1.13 2002/02/16 21:28:05 millert Exp $ */ +/* $OpenBSD: spec.c,v 1.14 2002/03/09 18:49:09 millert Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: spec.c,v 1.13 2002/02/16 21:28:05 millert Exp $"; +static const char rcsid[] = "$OpenBSD: spec.c,v 1.14 2002/03/09 18:49:09 millert Exp $"; #endif #endif /* not lint */ @@ -51,6 +51,7 @@ static const char rcsid[] = "$OpenBSD: spec.c,v 1.13 2002/02/16 21:28:05 millert #include <unistd.h> #include <stdio.h> #include <ctype.h> +#include <vis.h> #include "mtree.h" #include "extern.h" @@ -144,10 +145,14 @@ noparent: error("no parent node"); if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL) error("%s", strerror(errno)); *centry = ginfo; - (void)strcpy(centry->name, p); #define MAGIC "?*[" if (strpbrk(p, MAGIC)) centry->flags |= F_MAGIC; + if (strunvis(centry->name, p) == -1) { + fprintf(stderr, + "mtree: filename (%s) encoded incorrectly\n", p); + strcpy(centry->name, p); + } set(NULL, centry); if (!root) { |