Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/makefs/mtree.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#include <stddef.h> | #include <stddef.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <vis.h> | |||||
#include "makefs.h" | #include "makefs.h" | ||||
#ifndef ENOATTR | #ifndef ENOATTR | ||||
#define ENOATTR ENOMSG | #define ENOATTR ENOMSG | ||||
#endif | #endif | ||||
#define IS_DOT(nm) ((nm)[0] == '.' && (nm)[1] == '\0') | #define IS_DOT(nm) ((nm)[0] == '.' && (nm)[1] == '\0') | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | case '#': /* comment -- skip to end of line. */ | ||||
if (!esc) { | if (!esc) { | ||||
error = skip_to(fp, "\n"); | error = skip_to(fp, "\n"); | ||||
if (!error) | if (!error) | ||||
continue; | continue; | ||||
} | } | ||||
break; | break; | ||||
case '\\': | case '\\': | ||||
esc++; | esc++; | ||||
if (esc == 1) | |||||
continue; | |||||
break; | break; | ||||
case '`': | case '`': | ||||
case '\'': | case '\'': | ||||
case '"': | case '"': | ||||
if (esc) | if (esc) | ||||
break; | break; | ||||
if (qlvl == 0) { | if (qlvl == 0) { | ||||
qlvl++; | qlvl++; | ||||
Show All 28 Lines | case '\n': | ||||
*/ | */ | ||||
if (qlvl > 0) | if (qlvl > 0) | ||||
mtree_warning("quoted word straddles " | mtree_warning("quoted word straddles " | ||||
"onto next line."); | "onto next line."); | ||||
fi = SLIST_FIRST(&mtree_fileinfo); | fi = SLIST_FIRST(&mtree_fileinfo); | ||||
fi->line++; | fi->line++; | ||||
} | } | ||||
break; | break; | ||||
case 'a': | default: | ||||
if (esc) | if (esc) | ||||
c = '\a'; | buf[idx++] = '\\'; | ||||
break; | 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': | |||||
if (esc) | |||||
c = '\v'; | |||||
break; | |||||
} | } | ||||
buf[idx++] = c; | buf[idx++] = c; | ||||
esc = 0; | esc = 0; | ||||
} while (idx < bufsz && !done); | } while (idx < bufsz && !done); | ||||
if (idx >= bufsz) { | if (idx >= bufsz) { | ||||
mtree_error("word too long to fit buffer (max %zu characters)", | mtree_error("word too long to fit buffer (max %zu characters)", | ||||
bufsz); | bufsz); | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | case 'g': | ||||
error = ENOSYS; | error = ENOSYS; | ||||
break; | break; | ||||
case 'l': | case 'l': | ||||
if (strcmp(keyword, "link") == 0) { | if (strcmp(keyword, "link") == 0) { | ||||
if (value == NULL) { | if (value == NULL) { | ||||
error = ENOATTR; | error = ENOATTR; | ||||
break; | break; | ||||
} | } | ||||
node->symlink = estrdup(value); | node->symlink = emalloc(strlen(value) + 1); | ||||
node->symlink[0] = '\0'; | |||||
marcel: Stray assignment?
This is a dereference of node->symlink before checking for a NULL pointer... | |||||
if (node->symlink == NULL) { | |||||
error = errno; | |||||
break; | |||||
} | |||||
if (strunvis(node->symlink, value) < 0) { | |||||
error = errno; | |||||
break; | |||||
} | |||||
} else | } else | ||||
error = ENOSYS; | error = ENOSYS; | ||||
break; | break; | ||||
case 'm': | case 'm': | ||||
if (strcmp(keyword, "mode") == 0) { | if (strcmp(keyword, "mode") == 0) { | ||||
if (value == NULL) { | if (value == NULL) { | ||||
error = ENOATTR; | error = ENOATTR; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 363 Lines • ▼ Show 20 Lines | if (mtree_root == NULL) | ||||
mtree_root = node; | mtree_root = node; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
read_mtree_spec(FILE *fp) | read_mtree_spec(FILE *fp) | ||||
{ | { | ||||
char pathspec[PATH_MAX]; | char pathspec[PATH_MAX], pathtmp[4*PATH_MAX + 1]; | ||||
char *cp; | char *cp; | ||||
int error; | int error; | ||||
error = read_word(fp, pathspec, sizeof(pathspec)); | error = read_word(fp, pathtmp, sizeof(pathtmp)); | ||||
if (error) | if (error) | ||||
goto out; | goto out; | ||||
error = strnunvis(pathspec, PATH_MAX, pathtmp); | |||||
marcelUnsubmitted Done Inline ActionsMaybe just write: if (strnunvis(pathspec, PATH_MAX, pathtmp) == -1) { error = errno; goto out; } That avoids having to reset error and avoids confusion about the return value of strnunvis: it's not an error... marcel: Maybe just write:
```
if (strnunvis(pathspec, PATH_MAX, pathtmp) == -1) {
error = errno… | |||||
if (error < 0) { | |||||
error = errno; | |||||
goto out; | |||||
} | |||||
error = 0; | |||||
cp = strchr(pathspec, '/'); | cp = strchr(pathspec, '/'); | ||||
if (cp != NULL) { | if (cp != NULL) { | ||||
/* Absolute pathname */ | /* Absolute pathname */ | ||||
mtree_current = mtree_root; | mtree_current = mtree_root; | ||||
do { | do { | ||||
*cp++ = '\0'; | *cp++ = '\0'; | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |
Stray assignment?
This is a dereference of node->symlink before checking for a NULL pointer...