summaryrefslogtreecommitdiffstats
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
commit1a424591f0d787caa06b72793aca04d086543797 (patch)
treefa6d69ca5cb89115b4a475438faf5e0f18cc5353
parent27e18e334d378c849667dff75a929850bbcb7a1b (diff)
downloadmandoc-1a424591f0d787caa06b72793aca04d086543797.tar.gz
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.)
-rw-r--r--mdoc_validate.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index f752d263..48d1fd0f 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -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. */