diff -urpN mtree-3.7.20050808-freebsd-vis/lib/libc/gen/setmode.c mtree-3.7.20050808-fixes/lib/libc/gen/setmode.c --- mtree-3.7.20050808-freebsd-vis/lib/libc/gen/setmode.c Tue Mar 1 13:51:47 2005 +++ mtree-3.7.20050808-fixes/lib/libc/gen/setmode.c Mon Aug 8 07:19:51 2005 @@ -180,6 +180,8 @@ setmode(const char *p) if (!*p) return (NULL); + equalopdone = 0; + /* * Get a copy of the mask for the permissions that are mask relative. * Flip the bits, we want what's not set. Since it's possible that diff -urpN mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/compare.c mtree-3.7.20050808-fixes/usr.sbin/mtree/compare.c --- mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/compare.c Sun Nov 21 19:36:04 2004 +++ mtree-3.7.20050808-fixes/usr.sbin/mtree/compare.c Mon Aug 8 13:59:53 2005 @@ -226,7 +226,7 @@ typeerr: LABEL; } } if (s->flags & F_CKSUM) { - if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { + if ((fd = open(p->fts_accpath, MTREE_O_FLAGS, 0)) < 0) { LABEL; (void)printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); diff -urpN mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/create.c mtree-3.7.20050808-fixes/usr.sbin/mtree/create.c --- mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/create.c Sun Nov 21 19:36:04 2004 +++ mtree-3.7.20050808-fixes/usr.sbin/mtree/create.c Mon Aug 8 16:56:53 2005 @@ -70,7 +70,11 @@ static gid_t gid; static uid_t uid; static mode_t mode; -static void output(int, int *, const char *, ...); +static void output(int, int *, const char *, ...) +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif + ; static int statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *); static void statf(int, FTSENT *); @@ -145,8 +149,11 @@ statf(int indent, FTSENT *p) escaped_name = malloc(esc_len); if (escaped_name == NULL) error("statf: %s", strerror(errno)); - strnvis(escaped_name, p->fts_name, esc_len, VIS_WHITE | VIS_OCTAL); + strnvis(escaped_name, p->fts_name, esc_len, + VIS_WHITE | VIS_OCTAL | VIS_GLOB); + /* XXX: printf() may return -1 on error, which is not correctly + * handled throughout this source file */ if (iflag || S_ISDIR(p->fts_statp->st_mode)) offset = printf("%*s%s", indent, "", escaped_name); else @@ -196,7 +203,7 @@ statf(int indent, FTSENT *p) p->fts_statp->st_mtimespec.tv_sec, p->fts_statp->st_mtimespec.tv_nsec); if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { - if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || + if ((fd = open(p->fts_accpath, MTREE_O_FLAGS, 0)) < 0 || crc(fd, &val, &len)) error("%s: %s", p->fts_accpath, strerror(errno)); (void)close(fd); diff -urpN mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/extern.h mtree-3.7.20050808-fixes/usr.sbin/mtree/extern.h --- mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/extern.h Sun Nov 21 19:36:04 2004 +++ mtree-3.7.20050808-fixes/usr.sbin/mtree/extern.h Mon Aug 8 13:59:06 2005 @@ -39,7 +39,11 @@ int compare(char *, struct _node *, st int dsort(const struct _ftsent **, const struct _ftsent **); int crc(int, u_int32_t *, u_int32_t *); void cwalk(void); -void error(const char *, ...); +void error(const char *, ...) +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif + ; char *inotype(u_int); u_int parsekey(char *, int *); char *rlink(char *); diff -urpN mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/mtree.h mtree-3.7.20050808-fixes/usr.sbin/mtree/mtree.h --- mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/mtree.h Mon Jun 2 23:36:54 2003 +++ mtree-3.7.20050808-fixes/usr.sbin/mtree/mtree.h Mon Aug 8 13:58:18 2005 @@ -35,6 +35,9 @@ #include #include +#define MTREE_O_FLAGS \ + (O_RDONLY | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW) + #define KEYDEFAULT \ (F_GID | F_MODE | F_NLINK | F_SIZE | F_SLINK | F_TIME | F_UID) diff -urpN mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/spec.c mtree-3.7.20050808-fixes/usr.sbin/mtree/spec.c --- mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/spec.c Sun Aug 1 18:32:20 2004 +++ mtree-3.7.20050808-fixes/usr.sbin/mtree/spec.c Mon Aug 8 12:28:36 2005 @@ -59,7 +59,7 @@ NODE * spec(void) { NODE *centry, *last; - char *p; + char *p, *q; NODE ginfo, *root; int c_cur, c_next; char buf[2048]; @@ -74,25 +74,27 @@ spec(void) if (buf[0] == '\n') continue; + /* Skip leading whitespace. */ + for (p = buf; *p && isspace((unsigned char)*p); ++p); + /* Find end of line. */ - if ((p = strchr(buf, '\n')) == NULL) + q = p + strlen(p); + if (q >= buf + (sizeof(buf) - 1)) error("line %d too long", lineno); + /* If nothing but whitespace or comment char, continue. */ + if (!*p || *p == '\n' || *p == '#') + continue; + + /* Zap LF if present and position to last character. */ + if (*--q == '\n') + *q-- = '\0'; + /* See if next line is continuation line. */ - if (p[-1] == '\\') { - --p; + if (*q == '\\') { + *q = '\0'; c_next = 1; } - - /* Null-terminate the line. */ - *p = '\0'; - - /* Skip leading whitespace. */ - for (p = buf; *p && isspace(*p); ++p); - - /* If nothing but whitespace or comment char, continue. */ - if (!*p || *p == '#') - continue; #ifdef DEBUG (void)fprintf(stderr, "line %d: {%s}\n", lineno, p); diff -urpN mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/verify.c mtree-3.7.20050808-fixes/usr.sbin/mtree/verify.c --- mtree-3.7.20050808-freebsd-vis/usr.sbin/mtree/verify.c Sun Nov 21 19:36:04 2004 +++ mtree-3.7.20050808-fixes/usr.sbin/mtree/verify.c Mon Aug 8 13:55:55 2005 @@ -163,6 +163,7 @@ miss(NODE *p, char *tail, size_t len) continue; if (p->type != F_DIR && (dflag || p->flags & F_VISIT)) continue; + /* XXX: pathname truncation on overflow */ (void)strlcpy(tail, p->name, len); if (!(p->flags & F_VISIT)) { /* Don't print missing message if file exists as a @@ -201,6 +202,7 @@ miss(NODE *p, char *tail, size_t len) for (tp = tail; *tp; ++tp); *tp = '/'; + /* XXX: may overflow */ miss(p->child, tp + 1, len - (tp + 1 - tail)); *tp = '\0';