summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2012-07-12 15:09:51 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2012-07-12 15:09:51 +0000
commit3346b5b6c795f44f3b15c48768f03764b37716fe (patch)
treebc265c63155c1a1a6e4d476b0070e58e12e63ac9 /usr.bin
parent4f3b6898a0d56413863db3c64265f241dc1013ab (diff)
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.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/mandoc.h4
-rw-r--r--usr.bin/mandoc/mdoc_validate.c31
-rw-r--r--usr.bin/mandoc/read.c4
3 files changed, 22 insertions, 17 deletions
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index e91f2e7bf2e..2e615dd4fac 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.46 2012/05/28 13:00:51 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.47 2012/07/12 15:09:50 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -61,7 +61,6 @@ enum mandocerr {
MANDOCERR_SO, /* .so is fragile, better use ln(1) */
MANDOCERR_NAMESECFIRST, /* NAME section must come first */
MANDOCERR_BADNAMESEC, /* bad NAME section contents */
- MANDOCERR_NONAME, /* manual name not yet set */
MANDOCERR_SECOOO, /* sections out of conventional order */
MANDOCERR_SECREP, /* duplicate section name */
MANDOCERR_SECMSEC, /* section not in conventional manual section */
@@ -129,6 +128,7 @@ enum mandocerr {
MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
MANDOCERR_BADCHAR, /* skipping bad character */
MANDOCERR_NAMESC, /* escaped character not allowed in a name */
+ MANDOCERR_NONAME, /* manual name not yet set */
MANDOCERR_NOTEXT, /* skipping text before the first section header */
MANDOCERR_MACRO, /* skipping unknown macro */
MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index e12a9b76ce9..3f29cf00c75 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.104 2012/07/11 16:55:29 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.105 2012/07/12 15:09:50 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -1119,24 +1119,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);
}
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index e70ff17655d..38218aae620 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.8 2012/06/02 23:18:30 schwarze Exp $ */
+/* $Id: read.c,v 1.9 2012/07/12 15:09:50 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -95,7 +95,6 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
".so is fragile, better use ln(1)",
"NAME section must come first",
"bad NAME section contents",
- "manual name not yet set",
"sections out of conventional order",
"duplicate section name",
"section not in conventional manual section",
@@ -163,6 +162,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"input stack limit exceeded, infinite loop?",
"skipping bad character",
"escaped character not allowed in a name",
+ "manual name not yet set",
"skipping text before the first section header",
"skipping unknown macro",
"NOT IMPLEMENTED, please use groff: skipping request",