=================================================================== RCS file: /cvs/mandoc/compat_fts.c,v retrieving revision 1.9 retrieving revision 1.11 diff -u -p -r1.9 -r1.11 --- mandoc/compat_fts.c 2015/03/18 19:29:48 1.9 +++ mandoc/compat_fts.c 2016/10/18 23:13:25 1.11 @@ -6,8 +6,8 @@ int dummy; #else -/* $Id: compat_fts.c,v 1.9 2015/03/18 19:29:48 schwarze Exp $ */ -/* $OpenBSD: compat_fts.c,v 1.9 2015/03/18 19:29:48 schwarze Exp $ */ +/* $Id: compat_fts.c,v 1.11 2016/10/18 23:13:25 schwarze Exp $ */ +/* $OpenBSD: compat_fts.c,v 1.11 2016/10/18 23:13:25 schwarze Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -68,6 +68,9 @@ static unsigned short fts_stat(FTS *, FTSENT *); #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif #define CLR(opt) (sp->fts_options &= ~(opt)) #define ISSET(opt) (sp->fts_options & (opt)) @@ -80,7 +83,6 @@ fts_open(char * const *argv, int options, void *dummy) FTSENT *p, *root; int nitems; FTSENT *parent, *tmp; - size_t len; /* Options check. */ if (options & ~FTS_OPTIONMASK) { @@ -88,6 +90,12 @@ fts_open(char * const *argv, int options, void *dummy) return (NULL); } + /* At least one path must be specified. */ + if (*argv == NULL) { + errno = EINVAL; + return (NULL); + } + /* Allocate/initialize the stream */ if ((sp = calloc(1, sizeof(FTS))) == NULL) return (NULL); @@ -107,14 +115,8 @@ fts_open(char * const *argv, int options, void *dummy) /* Allocate/initialize root(s). */ for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; + if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL) goto mem3; - } - - if ((p = fts_alloc(sp, *argv, len)) == NULL) - goto mem3; p->fts_level = FTS_ROOTLEVEL; p->fts_parent = parent; p->fts_accpath = p->fts_name; @@ -317,7 +319,6 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent); * semantics to fts using fts_set. An error return is allowed for similar * reasons. */ -/* ARGSUSED */ int fts_set(FTS *sp, FTSENT *p, int instr) { @@ -416,8 +417,7 @@ fts_build(FTS *sp) * structures already allocated. */ mem1: saved_errno = errno; - if (p) - free(p); + free(p); fts_lfree(head); (void)closedir(dirp); cur->fts_info = FTS_ERR; @@ -597,8 +597,7 @@ fts_palloc(FTS *sp, size_t more) */ more += 256; if (sp->fts_pathlen + more < sp->fts_pathlen) { - if (sp->fts_path) - free(sp->fts_path); + free(sp->fts_path); sp->fts_path = NULL; errno = ENAMETOOLONG; return (1); @@ -606,8 +605,7 @@ fts_palloc(FTS *sp, size_t more) sp->fts_pathlen += more; p = realloc(sp->fts_path, sp->fts_pathlen); if (p == NULL) { - if (sp->fts_path) - free(sp->fts_path); + free(sp->fts_path); sp->fts_path = NULL; return (1); }