summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-09-18 15:22:08 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-09-18 15:22:08 +0000
commit8a61fa80efe1c661e0711f10bfc0cca6bad267fa (patch)
treeeb7ae709391cb9fa0a199a4945f9c7891005d62a /main.c
parent9949d36709dfa327c4b68d56f682e094b09c9d60 (diff)
downloadmandoc-8a61fa80efe1c661e0711f10bfc0cca6bad267fa.tar.gz
Make sure an output device is allocated before calling terminal_sepline(),
fixing a NULL pointer access that happened when the first of multiple pages shown was preformatted, as in "man -a groff troff". Crash reported by <jmates at ee dot washington dot edu> on bugs@, thanks!
Diffstat (limited to 'main.c')
-rw-r--r--main.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/main.c b/main.c
index ebf08a4c..2c1ccfcd 100644
--- a/main.c
+++ b/main.c
@@ -95,6 +95,7 @@ static int koptions(int *, char *);
static int moptions(int *, char *);
static void mmsg(enum mandocerr, enum mandoclevel,
const char *, int, int, const char *);
+static void outdata_alloc(struct curparse *);
static void parse(struct curparse *, int, const char *);
static void passthrough(const char *, int, int);
static pid_t spawn_pager(struct tag_files *);
@@ -465,8 +466,11 @@ main(int argc, char *argv[])
passthrough(resp->file, fd,
conf.output.synopsisonly);
- if (argc > 1 && curp.outtype <= OUTT_UTF8)
+ if (argc > 1 && curp.outtype <= OUTT_UTF8) {
+ if (curp.outdata == NULL)
+ outdata_alloc(&curp);
terminal_sepline(curp.outdata);
+ }
} else if (rc < MANDOCLEVEL_ERROR)
rc = MANDOCLEVEL_ERROR;
@@ -722,32 +726,8 @@ parse(struct curparse *curp, int fd, const char *file)
if (rctmp != MANDOCLEVEL_OK && curp->wstop)
return;
- /* If unset, allocate output dev now (if applicable). */
-
- if (curp->outdata == NULL) {
- switch (curp->outtype) {
- case OUTT_HTML:
- curp->outdata = html_alloc(curp->outopts);
- break;
- case OUTT_UTF8:
- curp->outdata = utf8_alloc(curp->outopts);
- break;
- case OUTT_LOCALE:
- curp->outdata = locale_alloc(curp->outopts);
- break;
- case OUTT_ASCII:
- curp->outdata = ascii_alloc(curp->outopts);
- break;
- case OUTT_PDF:
- curp->outdata = pdf_alloc(curp->outopts);
- break;
- case OUTT_PS:
- curp->outdata = ps_alloc(curp->outopts);
- break;
- default:
- break;
- }
- }
+ if (curp->outdata == NULL)
+ outdata_alloc(curp);
mparse_result(curp->mp, &man, NULL);
@@ -804,6 +784,33 @@ parse(struct curparse *curp, int fd, const char *file)
}
static void
+outdata_alloc(struct curparse *curp)
+{
+ switch (curp->outtype) {
+ case OUTT_HTML:
+ curp->outdata = html_alloc(curp->outopts);
+ break;
+ case OUTT_UTF8:
+ curp->outdata = utf8_alloc(curp->outopts);
+ break;
+ case OUTT_LOCALE:
+ curp->outdata = locale_alloc(curp->outopts);
+ break;
+ case OUTT_ASCII:
+ curp->outdata = ascii_alloc(curp->outopts);
+ break;
+ case OUTT_PDF:
+ curp->outdata = pdf_alloc(curp->outopts);
+ break;
+ case OUTT_PS:
+ curp->outdata = ps_alloc(curp->outopts);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
passthrough(const char *file, int fd, int synopsis_only)
{
const char synb[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";