From owner-freebsd-bugs Fri Mar 8 14:50:49 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id D4DAC37B43F for ; Fri, 8 Mar 2002 14:50:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g28Mo1d06043; Fri, 8 Mar 2002 14:50:01 -0800 (PST) (envelope-from gnats) Date: Fri, 8 Mar 2002 14:50:01 -0800 (PST) Message-Id: <200203082250.g28Mo1d06043@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Nicolas Rachinsky Subject: Re: bin/35454: mtree can't handle symlinks referencing files which names contain spaces Reply-To: Nicolas Rachinsky Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/35454; it has been noted by GNATS. From: Nicolas Rachinsky To: freebsd-gnats-submit@FreeBSD.org Cc: Subject: Re: bin/35454: mtree can't handle symlinks referencing files which names contain spaces Date: Fri, 8 Mar 2002 23:47:04 +0100 I've just created this patch which seems to solve the problem: Index: create.c =================================================================== RCS file: /usr/cvs-freebsd/src/usr.sbin/mtree/create.c,v retrieving revision 1.18.2.3 diff -u -r1.18.2.3 create.c --- create.c 12 Jan 2001 19:17:18 -0000 1.18.2.3 +++ create.c 8 Mar 2002 22:38:18 -0000 @@ -154,7 +154,7 @@ u_long len, val; int fd, offset; char *fflags; - char *escaped_name; + char *escaped_name,*s; escaped_name = calloc(1, p->fts_namelen * 4 + 1); if (escaped_name == NULL) @@ -256,7 +256,18 @@ #endif /* RMD160 */ if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) - output(indent, &offset, "link=%s", rlink(p->fts_accpath)); + { + s=strdup(rlink(p->fts_accpath)); + if(!s) + errx(1, "statf(): strdup() failed"); + escaped_name = calloc(1, strlen(s) * 4 + 1); + if (escaped_name == NULL) + errx(1, "statf(): calloc() failed"); + strvis(escaped_name, s, VIS_WHITE | VIS_OCTAL); + output(indent, &offset, "link=%s", escaped_name); + free(escaped_name); + free(s); + } if (keys & F_FLAGS && p->fts_statp->st_flags != flags) { fflags = flags_to_string(p->fts_statp->st_flags); output(indent, &offset, "flags=%s", fflags); Index: spec.c =================================================================== RCS file: /usr/cvs-freebsd/src/usr.sbin/mtree/spec.c,v retrieving revision 1.13.2.1 diff -u -r1.13.2.1 spec.c --- spec.c 28 Jun 2000 02:33:17 -0000 1.13.2.1 +++ spec.c 8 Mar 2002 22:40:21 -0000 @@ -181,6 +181,7 @@ mode_t *m; int value; char *ep; + char *escaped_string; for (; (kw = strtok(t, "= \t\n")); t = NULL) { ip->flags |= type = parsekey(kw, &value); @@ -250,8 +251,16 @@ lineno, val); break; case F_SLINK: - if ((ip->slink = strdup(val)) == NULL) + if ((escaped_string = strdup(val)) == NULL) errx(1, "strdup"); + if((ip->slink=calloc(1, strlen(escaped_string) + 1)) == NULL) + errx(1, "set(): calloc() failed"); + if (strunvis(ip->slink, escaped_string) == -1) { + warnx("filename %s is ill-encoded and literally used", + escaped_string); + strcpy(ip->slink, escaped_string); + } + free(escaped_string); break; case F_TIME: ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message