summaryrefslogtreecommitdiffstats
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
commita350521d8151422ac228e507357343fe53d34ea1 (patch)
treeee5a93d6b5715b17dd39891fa0cc994859cec7eb
parente5162e81380b9a4f3a519fe614576af26589f06f (diff)
downloadmandoc-a350521d8151422ac228e507357343fe53d34ea1.tar.gz
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.
-rw-r--r--mdoc_macro.c4
-rw-r--r--mdoc_term.c15
2 files changed, 12 insertions, 7 deletions
diff --git a/mdoc_macro.c b/mdoc_macro.c
index acc9c68c..e62b76cb 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -437,9 +437,11 @@ rew_dohalt(enum mdoct tok, enum mdoc_type type,
* Default block rewinding rules.
* In particular, always skip block end markers,
* and let all blocks rewind Nm children.
+ * Do not warn again when closing a block,
+ * since closing the body already warned.
*/
if (ENDBODY_NOT != p->end || MDOC_Nm == p->tok ||
- (MDOC_BLOCK == p->type &&
+ MDOC_BLOCK == type || (MDOC_BLOCK == p->type &&
! (MDOC_EXPLICIT & mdoc_macros[tok].flags)))
return(REWIND_MORE);
diff --git a/mdoc_term.c b/mdoc_term.c
index 8f440733..af662bc3 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -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);