aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/makefs
diff options
context:
space:
mode:
authorBenno Rice <benno@FreeBSD.org>2017-08-25 16:10:16 +0000
committerBenno Rice <benno@FreeBSD.org>2017-08-25 16:10:16 +0000
commit88e2cc9eb56b714ac4e9f4cb064dc44a914bf773 (patch)
treee0c84c0cddc57c8d2fc09601b4bdb7aca35d654e /usr.sbin/makefs
parent77a798b30ae43e8aac56a124e159b0b8624f4195 (diff)
downloadsrc-88e2cc9eb56b714ac4e9f4cb064dc44a914bf773.tar.gz
src-88e2cc9eb56b714ac4e9f4cb064dc44a914bf773.zip
Replace makefs' hand-rolled unescaping with strunvis
mtree path names and link attributes are encoded, generally using strvis. Newer versions of mtree will use C-style escapes but previously the accepted form was octal escapes. makefs' mtree code spots the C-style escapes but fails to deal with octal escapes correctly. Remove mtree's escape-decoding code (except for a few instances where it's needed) and instead pass pathnames and link targets through strunvis prior to use. Reviewed by: marcel MFC after: 2 weeks Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D12104
Notes
Notes: svn path=/head/; revision=322894
Diffstat (limited to 'usr.sbin/makefs')
-rw-r--r--usr.sbin/makefs/mtree.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/usr.sbin/makefs/mtree.c b/usr.sbin/makefs/mtree.c
index 69d3f516ea56..4d855d436634 100644
--- a/usr.sbin/makefs/mtree.c
+++ b/usr.sbin/makefs/mtree.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <time.h>
#include <unistd.h>
#include <util.h>
+#include <vis.h>
#include "makefs.h"
@@ -355,8 +356,6 @@ read_word(FILE *fp, char *buf, size_t bufsz)
break;
case '\\':
esc++;
- if (esc == 1)
- continue;
break;
case '`':
case '\'':
@@ -401,33 +400,9 @@ read_word(FILE *fp, char *buf, size_t bufsz)
fi->line++;
}
break;
- case 'a':
- if (esc)
- c = '\a';
- break;
- case 'b':
- if (esc)
- c = '\b';
- break;
- case 'f':
- if (esc)
- c = '\f';
- break;
- case 'n':
- if (esc)
- c = '\n';
- break;
- case 'r':
- if (esc)
- c = '\r';
- break;
- case 't':
- if (esc)
- c = '\t';
- break;
- case 'v':
+ default:
if (esc)
- c = '\v';
+ buf[idx++] = '\\';
break;
}
buf[idx++] = c;
@@ -591,7 +566,15 @@ read_mtree_keywords(FILE *fp, fsnode *node)
error = ENOATTR;
break;
}
- node->symlink = estrdup(value);
+ node->symlink = emalloc(strlen(value) + 1);
+ if (node->symlink == NULL) {
+ error = errno;
+ break;
+ }
+ if (strunvis(node->symlink, value) < 0) {
+ error = errno;
+ break;
+ }
} else
error = ENOSYS;
break;
@@ -971,13 +954,18 @@ read_mtree_spec1(FILE *fp, bool def, const char *name)
static int
read_mtree_spec(FILE *fp)
{
- char pathspec[PATH_MAX];
+ char pathspec[PATH_MAX], pathtmp[4*PATH_MAX + 1];
char *cp;
int error;
- error = read_word(fp, pathspec, sizeof(pathspec));
+ error = read_word(fp, pathtmp, sizeof(pathtmp));
if (error)
goto out;
+ if (strnunvis(pathspec, PATH_MAX, pathtmp) == -1) {
+ error = errno;
+ goto out;
+ }
+ error = 0;
cp = strchr(pathspec, '/');
if (cp != NULL) {