From 10c0052ec4ac1d18a7c1d6025ce3f9ffb1440cb6 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 30 Oct 2003 12:03:25 +0000 Subject: Use vis(3) to encode/decode the target for symlinks. Make vis(3) decode errors fatal for both symlink targets and fienames. --- usr.sbin/mtree/compare.c | 9 ++++++--- usr.sbin/mtree/spec.c | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'usr.sbin/mtree') diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index 33683f5..8fad8a4 100644 --- a/usr.sbin/mtree/compare.c +++ b/usr.sbin/mtree/compare.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -350,11 +351,13 @@ ftype(u_int type) char * rlink(char *name) { - static char lbuf[MAXPATHLEN]; + char tbuf[MAXPATHLEN]; + static char lbuf[MAXPATHLEN * 4]; int len; - if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1) + if ((len = readlink(name, tbuf, sizeof(tbuf) - 1)) == -1) err(1, "line %d: %s", lineno, name); - lbuf[len] = '\0'; + tbuf[len] = '\0'; + strvis(lbuf, tbuf, VIS_WHITE | VIS_OCTAL); return (lbuf); } diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 230847d..71038da 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -143,11 +143,8 @@ noparent: errx(1, "line %d: no parent node", lineno); #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); - } + if (strunvis(centry->name, p) == -1) + errx(1, "filename %s is ill-encoded", p); set(NULL, centry); if (!root) { @@ -244,8 +241,11 @@ set(char *t, NODE *ip) lineno, val); break; case F_SLINK: - if ((ip->slink = strdup(val)) == NULL) - errx(1, "strdup"); + ip->slink = malloc(strlen(val)); + if (ip->slink == NULL) + errx(1, "malloc"); + if (strunvis(ip->slink, val) == -1) + errx(1, "symlink %s is ill-encoded", val); break; case F_TIME: ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10); -- cgit v1.1