=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.213 retrieving revision 1.220 diff -u -p -r1.213 -r1.220 --- mandoc/mandocdb.c 2016/01/08 02:53:13 1.213 +++ mandoc/mandocdb.c 2016/07/19 13:36:13 1.220 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.213 2016/01/08 02:53:13 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.220 2016/07/19 13:36:13 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2016 Ingo Schwarze @@ -33,8 +33,10 @@ #else #include "compat_fts.h" #endif -#include #include +#if HAVE_SANDBOX_INIT +#include +#endif #include #include #include @@ -137,6 +139,9 @@ struct mdoc_handler { uint64_t mask; /* set unless handler returns 0 */ }; + +int mandocdb(int, char *[]); + static void dbclose(int); static void dbadd(struct mpage *); static void dbadd_mlink(const struct mlink *mlink); @@ -180,7 +185,8 @@ static void putkeys(const struct mpage *, char *, siz static void putmdockey(const struct mpage *, const struct roff_node *, uint64_t); static int render_string(char **, size_t *); -static void say(const char *, const char *, ...); +static void say(const char *, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); static int set_basedir(const char *, int); static int treescan(void); static size_t utf8(unsigned int, char [7]); @@ -341,11 +347,18 @@ mandocdb(int argc, char *argv[]) #if HAVE_PLEDGE if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) { - perror("pledge"); + warn("pledge"); return (int)MANDOCLEVEL_SYSERR; } #endif +#if HAVE_SANDBOX_INIT + if (sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, NULL) == -1) { + warnx("sandbox_init"); + return (int)MANDOCLEVEL_SYSERR; + } +#endif + memset(&conf, 0, sizeof(conf)); memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *)); @@ -422,7 +435,7 @@ mandocdb(int argc, char *argv[]) #if HAVE_PLEDGE if (nodb) { if (pledge("stdio rpath", NULL) == -1) { - perror("pledge"); + warn("pledge"); return (int)MANDOCLEVEL_SYSERR; } } @@ -456,7 +469,7 @@ mandocdb(int argc, char *argv[]) #if HAVE_PLEDGE if (!nodb) { if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) { - perror("pledge"); + warn("pledge"); exitcode = (int)MANDOCLEVEL_SYSERR; goto out; } @@ -574,7 +587,7 @@ usage: * or * [./]cat
[/]/.0 * - * TODO: accomodate for multi-language directories. + * TODO: accommodate for multi-language directories. */ static int treescan(void) @@ -1446,7 +1459,7 @@ parse_man(struct mpage *mpage, const struct roff_meta char byte; size_t sz; - if (NULL == n) + if (n == NULL) return; /* @@ -1458,13 +1471,12 @@ parse_man(struct mpage *mpage, const struct roff_meta if (n->type == ROFFT_BODY && n->tok == MAN_SH) { body = n; - assert(body->parent); - if (NULL != (head = body->parent->head) && - 1 == head->nchild && - NULL != (head = (head->child)) && + if ((head = body->parent->head) != NULL && + (head = head->child) != NULL && + head->next == NULL && head->type == ROFFT_TEXT && - 0 == strcmp(head->string, "NAME") && - NULL != body->child) { + strcmp(head->string, "NAME") == 0 && + body->child != NULL) { /* * Suck the entire NAME section into memory. @@ -1697,7 +1709,9 @@ parse_mdoc_Va(struct mpage *mpage, const struct roff_m if (n->type != ROFFT_ELEM && n->type != ROFFT_BODY) return 0; - if (n->nchild == 1 && n->child->type == ROFFT_TEXT) + if (n->child != NULL && + n->child->next == NULL && + n->child->type == ROFFT_TEXT) return 1; cp = NULL; @@ -1805,7 +1819,7 @@ putkeys(const struct mpage *mpage, char *cp, size_t sz name_mask &= ~NAME_FIRST; if (debug > 1) say(mpage->mlinks->file, - "Adding name %*s, bits=%d", sz, cp, v); + "Adding name %*s, bits=0x%llu", (int)sz, cp, v); } else { htab = &strings; if (debug > 1) @@ -1813,7 +1827,7 @@ putkeys(const struct mpage *mpage, char *cp, size_t sz if ((uint64_t)1 << i & v) say(mpage->mlinks->file, "Adding key %s=%*s", - mansearch_keynames[i], sz, cp); + mansearch_keynames[i], (int)sz, cp); } end = cp + sz;