Date: Fri, 8 Mar 2002 14:50:01 -0800 (PST) From: Nicolas Rachinsky <list@rachinsky.de> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/35454: mtree can't handle symlinks referencing files which names contain spaces Message-ID: <200203082250.g28Mo1d06043@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/35454; it has been noted by GNATS. From: Nicolas Rachinsky <list@rachinsky.de> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203082250.g28Mo1d06043>