summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-09-18 15:21:01 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-09-18 15:21:01 +0000
commite52040f93798267a8110083127b32896f8960650 (patch)
treef88c38bf8f646844c63c24b8ed0cc4525432c91a /usr.bin/mandoc
parent2723afe21c17425f143489aecfdd457976aac5f8 (diff)
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 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/main.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index c2208c9d0d8..1a0602882e1 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.178 2016/08/09 15:08:15 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.179 2016/09/18 15:21:00 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org>
@@ -89,6 +89,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 *);
@@ -435,8 +436,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;
@@ -692,32 +696,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);
@@ -774,6 +754,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";