diff options
author | bdrewery <bdrewery@FreeBSD.org> | 2018-02-02 21:00:06 +0000 |
---|---|---|
committer | bdrewery <bdrewery@FreeBSD.org> | 2018-02-02 21:00:06 +0000 |
commit | f205d4efbec3c0d8f5cd5edbc11db6c713a58ca6 (patch) | |
tree | 60b9da81c602c1caf6679a743d15bbbd4da7bb8c | |
parent | 30915abc08d28c1240eba05ab621b7620cd2c0a4 (diff) | |
download | FreeBSD-src-f205d4efbec3c0d8f5cd5edbc11db6c713a58ca6.zip FreeBSD-src-f205d4efbec3c0d8f5cd5edbc11db6c713a58ca6.tar.gz |
MFC r322894:
Replace makefs' hand-rolled unescaping with strunvis
Sponsored by: Dell EMC
-rw-r--r-- | usr.sbin/makefs/mtree.c | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/usr.sbin/makefs/mtree.c b/usr.sbin/makefs/mtree.c index 532b9e4..64bcb3b 100644 --- a/usr.sbin/makefs/mtree.c +++ b/usr.sbin/makefs/mtree.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <strings.h> #include <unistd.h> +#include <vis.h> #include "makefs.h" @@ -359,8 +360,6 @@ read_word(FILE *fp, char *buf, size_t bufsz) break; case '\\': esc++; - if (esc == 1) - continue; break; case '`': case '\'': @@ -405,33 +404,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; @@ -607,7 +582,15 @@ read_mtree_keywords(FILE *fp, fsnode *node) error = ENOATTR; break; } - node->symlink = strdup(value); + node->symlink = malloc(strlen(value) + 1); + if (node->symlink == NULL) { + error = errno; + break; + } + if (strunvis(node->symlink, value) < 0) { + error = errno; + break; + } } else error = ENOSYS; break; @@ -987,13 +970,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) { |