=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.206 retrieving revision 1.210 diff -u -p -r1.206 -r1.210 --- mandoc/mandocdb.c 2015/11/06 16:30:33 1.206 +++ mandoc/mandocdb.c 2015/12/15 17:38:45 1.210 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.206 2015/11/06 16:30:33 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.210 2015/12/15 17:38:45 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2015 Ingo Schwarze @@ -23,7 +23,9 @@ #include #include +#if HAVE_ERR #include +#endif #include #include #if HAVE_FTS @@ -337,6 +339,13 @@ mandocdb(int argc, char *argv[]) size_t j, sz; int ch, i; +#if HAVE_PLEDGE + if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) { + perror("pledge"); + return (int)MANDOCLEVEL_SYSERR; + } +#endif + memset(&conf, 0, sizeof(conf)); memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *)); @@ -410,6 +419,15 @@ mandocdb(int argc, char *argv[]) argc -= optind; argv += optind; +#if HAVE_PLEDGE + if (nodb) { + if (pledge("stdio rpath", NULL) == -1) { + perror("pledge"); + return (int)MANDOCLEVEL_SYSERR; + } + } +#endif + if (OP_CONFFILE == op && argc > 0) { warnx("-C: Too many arguments"); goto usage; @@ -435,6 +453,15 @@ mandocdb(int argc, char *argv[]) * The existing database is usable. Process * all files specified on the command-line. */ +#if HAVE_PLEDGE + if (!nodb) { + if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) { + perror("pledge"); + exitcode = (int)MANDOCLEVEL_SYSERR; + goto out; + } + } +#endif use_all = 1; for (i = 0; i < argc; i++) filescan(argv[i]); @@ -1267,7 +1294,9 @@ parse_cat(struct mpage *mpage, int fd) { FILE *stream; char *line, *p, *title; - size_t len, plen, titlesz; + size_t linesz, plen, titlesz; + ssize_t len; + int offs; stream = (-1 == fd) ? fopen(mpage->mlinks->file, "r") : @@ -1280,10 +1309,13 @@ parse_cat(struct mpage *mpage, int fd) return; } + line = NULL; + linesz = 0; + /* Skip to first blank line. */ - while (NULL != (line = fgetln(stream, &len))) - if ('\n' == *line) + while (getline(&line, &linesz, stream) != -1) + if (*line == '\n') break; /* @@ -1291,8 +1323,8 @@ parse_cat(struct mpage *mpage, int fd) * is the first section header. Skip to it. */ - while (NULL != (line = fgetln(stream, &len))) - if ('\n' != *line && ' ' != *line) + while (getline(&line, &linesz, stream) != -1) + if (*line != '\n' && *line != ' ') break; /* @@ -1305,20 +1337,20 @@ parse_cat(struct mpage *mpage, int fd) titlesz = 0; title = NULL; - while (NULL != (line = fgetln(stream, &len))) { - if (' ' != *line || '\n' != line[len - 1]) + while ((len = getline(&line, &linesz, stream)) != -1) { + if (*line != ' ') break; - while (len > 0 && isspace((unsigned char)*line)) { - line++; - len--; - } - if (1 == len) + offs = 0; + while (isspace((unsigned char)line[offs])) + offs++; + if (line[offs] == '\0') continue; - title = mandoc_realloc(title, titlesz + len); - memcpy(title + titlesz, line, len); - titlesz += len; + title = mandoc_realloc(title, titlesz + len - offs); + memcpy(title + titlesz, line + offs, len - offs); + titlesz += len - offs; title[titlesz - 1] = ' '; } + free(line); /* * If no page content can be found, or the input line @@ -1336,8 +1368,7 @@ parse_cat(struct mpage *mpage, int fd) return; } - title = mandoc_realloc(title, titlesz + 1); - title[titlesz] = '\0'; + title[titlesz - 1] = '\0'; /* * Skip to the first dash.