summaryrefslogtreecommitdiffstats
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2012-07-12 15:11:14 +0000
committerIngo Schwarze <schwarze@openbsd.org>2012-07-12 15:11:14 +0000
commit00dbc3009d4f54812c18b39ea2af11c5f2d1b31c (patch)
treefe7508be24a62c1d6f5ccc7988bc01217a90daea /mdoc_validate.c
parentb675b3b7a26a6ab613fd579cb59ce6997de5ec6d (diff)
downloadmandoc-00dbc3009d4f54812c18b39ea2af11c5f2d1b31c.tar.gz
The post_nm() validation function crashed when the first .Nm child node
was a non-text node. Fix this by rewriting post_nm() to always set the meta name to UNKNOWN when the name is missing or unusable. While here, make MANDOCERR_NONAME an ERROR, as it usually renders the page content unintelligible. Bug reported by Maxim <Belooussov at gmail dot com>, thanks. OpenBSD rev. 1.105
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 49d6f780..e8218d82 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1123,24 +1123,29 @@ post_nm(POST_ARGS)
char buf[BUFSIZ];
int c;
- /* If no child specified, make sure we have the meta name. */
-
- if (NULL == mdoc->last->child && NULL == mdoc->meta.name) {
- mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME);
- return(1);
- } else if (mdoc->meta.name)
+ if (NULL != mdoc->meta.name)
return(1);
- /* If no meta name, set it from the child. */
+ /* Try to use our children for setting the meta name. */
- buf[0] = '\0';
- if (-1 == (c = concat(buf, mdoc->last->child, BUFSIZ))) {
+ if (NULL != mdoc->last->child) {
+ buf[0] = '\0';
+ c = concat(buf, mdoc->last->child, BUFSIZ);
+ } else
+ c = 0;
+
+ switch (c) {
+ case (-1):
mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);
return(0);
+ case (0):
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME);
+ mdoc->meta.name = mandoc_strdup("UNKNOWN");
+ break;
+ default:
+ mdoc->meta.name = mandoc_strdup(buf);
+ break;
}
-
- assert(c);
- mdoc->meta.name = mandoc_strdup(buf);
return(1);
}