From f205d4efbec3c0d8f5cd5edbc11db6c713a58ca6 Mon Sep 17 00:00:00 2001 From: bdrewery Date: Fri, 2 Feb 2018 21:00:06 +0000 Subject: [PATCH] MFC r322894: Replace makefs' hand-rolled unescaping with strunvis Sponsored by: Dell EMC --- usr.sbin/makefs/mtree.c | 50 ++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/usr.sbin/makefs/mtree.c b/usr.sbin/makefs/mtree.c index 532b9e41f7a..64bcb3bef21 100644 --- a/usr.sbin/makefs/mtree.c +++ b/usr.sbin/makefs/mtree.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #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) { -- 2.45.0