aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-08-10 20:17:50 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-08-10 20:17:50 +0000
commitea968bc9dd55733b728f8cdfe266ee97c4fd2813 (patch)
treed74ca705b38844c618d718aed74bfc35468c8830 /mdoc_validate.c
parent7e7a3a3122db15e60fa9a6b4c17f2a4c23ac3b80 (diff)
downloadmandoc-ea968bc9dd55733b728f8cdfe266ee97c4fd2813.tar.gz
mandoc-ea968bc9dd55733b728f8cdfe266ee97c4fd2813.tar.zst
mandoc-ea968bc9dd55733b728f8cdfe266ee97c4fd2813.zip
Don't deref NULL if the only child of the first .Sh is an empty
in-line macro, and don't printf("%s", NULL) if the first child of the first .Sh is a macro; again found by tb@ with afl(1). (No, you should never use macros in any .Sh at all, please.)
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 214e98da..832832fb 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.304 2016/08/10 12:29:38 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.305 2016/08/10 20:17:50 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org>
@@ -1761,8 +1761,9 @@ post_sh_authors(POST_ARGS)
static void
post_sh_head(POST_ARGS)
{
- const char *goodsec;
- enum roff_sec sec;
+ struct roff_node *nch;
+ const char *goodsec;
+ enum roff_sec sec;
/*
* Process a new section. Sections are either "named" or
@@ -1778,8 +1779,10 @@ post_sh_head(POST_ARGS)
if (sec != SEC_NAME && mdoc->lastnamed == SEC_NONE)
mandoc_vmsg(MANDOCERR_NAMESEC_FIRST, mdoc->parse,
mdoc->last->line, mdoc->last->pos, "Sh %s",
- sec == SEC_CUSTOM ? mdoc->last->child->string :
- secnames[sec]);
+ sec != SEC_CUSTOM ? secnames[sec] :
+ (nch = mdoc->last->child) == NULL ? "" :
+ nch->type == ROFFT_TEXT ? nch->string :
+ mdoc_macronames[nch->tok]);
/* The SYNOPSIS gets special attention in other areas. */