aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit3e60e11433f93686186391d27f5b2c8104dac503 (patch)
treeaae81553cbb2743f0e03a3adc024e56dfbf3dcd9 /main.c
parentf9af2dc93167d66751a64bd05173086b7ec03e2d (diff)
downloadmandoc-3e60e11433f93686186391d27f5b2c8104dac503.tar.gz
mandoc-3e60e11433f93686186391d27f5b2c8104dac503.tar.zst
mandoc-3e60e11433f93686186391d27f5b2c8104dac503.zip
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.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/main.c b/main.c
index e240719b..02aa1968 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.275 2016/08/09 15:09:27 schwarze Exp $ */
+/* $Id: main.c,v 1.276 2016/09/18 15:22:08 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org>
@@ -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";