aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-11-25 20:00:01 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-11-25 20:00:01 +0000
commitb6eb32baf4f92507017b1af5af22cec2aed378ee (patch)
treef977905f85d4081796e4e7e2d54b4e1417a0fbcb /mdoc_term.c
parent6242a9efa48427465988912bdb7e56c75b239acf (diff)
downloadmandoc-b6eb32baf4f92507017b1af5af22cec2aed378ee.tar.gz
mandoc-b6eb32baf4f92507017b1af5af22cec2aed378ee.tar.zst
mandoc-b6eb32baf4f92507017b1af5af22cec2aed378ee.zip
Do not access a NULL pointer when a section has no body,
which can for example happen for .Sh Xo .Sh without .Xc. Crash found by jsg@ with afl.
Diffstat (limited to 'mdoc_term.c')
-rw-r--r--mdoc_term.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/mdoc_term.c b/mdoc_term.c
index 8db43b97..f1825ccd 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.292 2014/11/21 01:52:53 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.293 2014/11/25 20:00:01 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1374,14 +1374,17 @@ static int
termp_sh_pre(DECL_ARGS)
{
- /* No vspace between consecutive `Sh' calls. */
-
switch (n->type) {
case MDOC_BLOCK:
- if (n->prev && MDOC_Sh == n->prev->tok)
- if (NULL == n->prev->body->child)
- break;
- term_vspace(p);
+ /*
+ * Vertical space before sections, except
+ * when the previous section was empty.
+ */
+ if (n->prev == NULL ||
+ MDOC_Sh != n->prev->tok ||
+ (n->prev->body != NULL &&
+ n->prev->body->child != NULL))
+ term_vspace(p);
break;
case MDOC_HEAD:
term_fontpush(p, TERMFONT_BOLD);