diff options
author | 2017-01-08 00:10:22 +0000 | |
---|---|---|
committer | 2017-01-08 00:10:22 +0000 | |
commit | f27faacc13af7c108cb64e7d02bccedf5236d4c3 (patch) | |
tree | e4b6b8da667eafbcbcee0f611307a2ee6ea8dd95 | |
parent | Make getting the parent clock for the SD/MMC controller work on the (diff) | |
download | wireguard-openbsd-f27faacc13af7c108cb64e7d02bccedf5236d4c3.tar.xz wireguard-openbsd-f27faacc13af7c108cb64e7d02bccedf5236d4c3.zip |
Stricter validation of the NAME section, in particular:
- require a comma between names
- reject all other text nodes
- reject all empty Nm below NAME, not only in the leading position
- reject Nm after Nd
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Nd/broken.out_lint | 2 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/Makefile | 8 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/emptyNAME.out_lint | 2 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/orderNAME.in | 9 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_ascii | 12 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_lint | 2 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/punctNAME.in | 10 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_ascii | 10 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_lint | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.1 | 21 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 30 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 7 |
13 files changed, 95 insertions, 29 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Nd/broken.out_lint b/regress/usr.bin/mandoc/mdoc/Nd/broken.out_lint index 6606c52d020..2fc6732be6f 100644 --- a/regress/usr.bin/mandoc/mdoc/Nd/broken.out_lint +++ b/regress/usr.bin/mandoc/mdoc/Nd/broken.out_lint @@ -1,6 +1,6 @@ mandoc: broken.in:5:2: WARNING: bad NAME section content: Oo mandoc: broken.in:9:1: WARNING: bad NAME section content: text -mandoc: broken.in:4:2: WARNING: NAME section without name +mandoc: broken.in:4:2: WARNING: NAME section without Nm before Nd mandoc: broken.in:4:2: WARNING: NAME section without description mandoc: broken.in:13:2: WARNING: moving content out of list: Bl mandoc: broken.in:18:1: WARNING: moving content out of list: text diff --git a/regress/usr.bin/mandoc/mdoc/Sh/Makefile b/regress/usr.bin/mandoc/mdoc/Sh/Makefile index 9fdac3f1a9e..a1db1161c9b 100644 --- a/regress/usr.bin/mandoc/mdoc/Sh/Makefile +++ b/regress/usr.bin/mandoc/mdoc/Sh/Makefile @@ -1,7 +1,9 @@ -# $OpenBSD: Makefile,v 1.6 2015/02/06 01:07:07 schwarze Exp $ +# $OpenBSD: Makefile,v 1.7 2017/01/08 00:10:22 schwarze Exp $ -REGRESS_TARGETS = badNAME before empty emptyNAME first nohead order subbefore -LINT_TARGETS = badNAME before empty emptyNAME first nohead order subbefore +REGRESS_TARGETS = badNAME before empty emptyNAME first nohead order +REGRESS_TARGETS += orderNAME punctNAME subbefore +LINT_TARGETS = badNAME before empty emptyNAME first nohead order +LINT_TARGETS += orderNAME punctNAME subbefore SKIP_GROFF = subbefore first empty SKIP_ASCII = first diff --git a/regress/usr.bin/mandoc/mdoc/Sh/emptyNAME.out_lint b/regress/usr.bin/mandoc/mdoc/Sh/emptyNAME.out_lint index 0713bec9ee3..c6da49bb508 100644 --- a/regress/usr.bin/mandoc/mdoc/Sh/emptyNAME.out_lint +++ b/regress/usr.bin/mandoc/mdoc/Sh/emptyNAME.out_lint @@ -1,2 +1,2 @@ -mandoc: emptyNAME.in:4:2: WARNING: NAME section without name +mandoc: emptyNAME.in:4:2: WARNING: NAME section without Nm before Nd mandoc: emptyNAME.in:4:2: WARNING: NAME section without description diff --git a/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.in b/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.in new file mode 100644 index 00000000000..d8fa14525d3 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.in @@ -0,0 +1,9 @@ +.Dd January 7, 2017 +.Dt SH-ORDERNAME 1 +.Os OpenBSD +.Sh NAME +.Nd name after description in NAME section +.Ss subsection +.Nm Sh-orderNAME +.Sh DESCRIPTION +The order of Nm and Nd is wrong in the NAME section. diff --git a/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_ascii b/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_ascii new file mode 100644 index 00000000000..5e9e032fe2a --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_ascii @@ -0,0 +1,12 @@ +SH-ORDERNAME(1) General Commands Manual SH-ORDERNAME(1) + +NNAAMMEE + - name after description in NAME section + + ssuubbsseeccttiioonn + SShh--oorrddeerrNNAAMMEE + +DDEESSCCRRIIPPTTIIOONN + The order of Nm and Nd is wrong in the NAME section. + +OpenBSD January 7, 2017 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_lint b/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_lint new file mode 100644 index 00000000000..0049023dd80 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Sh/orderNAME.out_lint @@ -0,0 +1,2 @@ +mandoc: orderNAME.in:5:2: WARNING: description not at the end of NAME +mandoc: orderNAME.in:4:2: WARNING: NAME section without Nm before Nd diff --git a/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.in b/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.in new file mode 100644 index 00000000000..c34648b56ce --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.in @@ -0,0 +1,10 @@ +.Dd January 7, 2017 +.Dt SH-PUNCTNAME 1 +.Os OpenBSD +.Sh NAME +.Nm Sh-punctNAME +.Nm second_name ; +.Nm third_name , +.Nd wrong punctuation in the NAME section +.Sh DESCRIPTION +One comma is missing, and one is misplaced. diff --git a/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_ascii b/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_ascii new file mode 100644 index 00000000000..8b74eda5fe3 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_ascii @@ -0,0 +1,10 @@ +SH-PUNCTNAME(1) General Commands Manual SH-PUNCTNAME(1) + +NNAAMMEE + SShh--ppuunnccttNNAAMMEE sseeccoonndd__nnaammee; tthhiirrdd__nnaammee, - wrong punctuation in the NAME + section + +DDEESSCCRRIIPPTTIIOONN + One comma is missing, and one is misplaced. + +OpenBSD January 7, 2017 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_lint b/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_lint new file mode 100644 index 00000000000..9ed95e4e01b --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Sh/punctNAME.out_lint @@ -0,0 +1,4 @@ +mandoc: punctNAME.in:6:2: WARNING: missing comma before name: Nm second_name +mandoc: punctNAME.in:6:17: WARNING: bad NAME section content: text +mandoc: punctNAME.in:7:2: WARNING: missing comma before name: Nm third_name +mandoc: punctNAME.in:7:16: WARNING: bad NAME section content: text diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 92b3b331343..4c3e8742a11 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mandoc.1,v 1.91 2017/01/06 01:33:48 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.92 2017/01/08 00:10:22 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> -.\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> +.\" Copyright (c) 2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org> .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 6 2017 $ +.Dd $Mdocdate: January 8 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -809,11 +809,13 @@ This may confuse .Xr makewhatis 8 and .Xr apropos 1 . -.It Sy "NAME section without name" +.It Sy "NAME section without Nm before Nd" .Pq mdoc The NAME section does not contain any .Ic \&Nm -child macro. +child macro before the first +.Ic \&Nd +macro. .It Sy "NAME section without description" .Pq mdoc The NAME section lacks the mandatory @@ -830,6 +832,11 @@ The NAME section contains plain text or macros other than .Ic \&Nm and .Ic \&Nd . +.It Sy "missing comma before name" +.Pq mdoc +The NAME section contains an +.Ic \&Nm +macro that is neither the first one nor preceded by a comma. .It Sy "missing description line, using \(dq\(dq" .Pq mdoc The @@ -1622,8 +1629,8 @@ macro fails to specify the list type. .It Sy "missing manual name, using \(dq\(dq" .Pq mdoc The first call to -.Ic \&Nm -lacks the required argument. +.Ic \&Nm , +or any call in the NAME section, lacks the required argument. .It Sy "uname(3) system call failed, using UNKNOWN" .Pq mdoc The diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index c0e1ff4ca2d..0ad279eb667 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,7 +1,7 @@ -/* $OpenBSD: mandoc.h,v 1.153 2016/12/28 17:21:17 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.154 2017/01/08 00:10:22 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,10 +65,11 @@ enum mandocerr { MANDOCERR_DOC_EMPTY, /* no document body */ MANDOCERR_SEC_BEFORE, /* content before first section header: macro */ MANDOCERR_NAMESEC_FIRST, /* first section is not NAME: Sh title */ - MANDOCERR_NAMESEC_NONM, /* NAME section without name */ + MANDOCERR_NAMESEC_NONM, /* NAME section without Nm before Nd */ MANDOCERR_NAMESEC_NOND, /* NAME section without description */ MANDOCERR_NAMESEC_ND, /* description not at the end of NAME */ MANDOCERR_NAMESEC_BAD, /* bad NAME section content: macro */ + MANDOCERR_NAMESEC_PUNCT, /* missing comma before name: Nm name */ MANDOCERR_ND_EMPTY, /* missing description line, using "" */ MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */ MANDOCERR_SEC_REP, /* duplicate section title: Sh title */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index bbfc3b9cdfe..1f499cbfa87 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mdoc_validate.c,v 1.226 2016/12/28 17:21:17 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.227 2017/01/08 00:10:22 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -842,12 +842,11 @@ post_nm(POST_ARGS) n->last->tok == MDOC_Lp)) mdoc_node_relink(mdoc, n->last); - if (mdoc->meta.name != NULL) - return; - - deroff(&mdoc->meta.name, n); - if (mdoc->meta.name == NULL) + deroff(&mdoc->meta.name, n); + + if (mdoc->meta.name == NULL || + (mdoc->lastsec == SEC_NAME && n->child == NULL)) mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse, n->line, n->pos, "Nm"); } @@ -1589,8 +1588,12 @@ post_sh_name(POST_ARGS) for (n = mdoc->last->child; n != NULL; n = n->next) { switch (n->tok) { case MDOC_Nm: + if (hasnm && n->child != NULL) + mandoc_vmsg(MANDOCERR_NAMESEC_PUNCT, + mdoc->parse, n->line, n->pos, + "Nm %s", n->child->string); hasnm = 1; - break; + continue; case MDOC_Nd: hasnd = 1; if (n->next != NULL) @@ -1598,14 +1601,19 @@ post_sh_name(POST_ARGS) mdoc->parse, n->line, n->pos, NULL); break; case TOKEN_NONE: - if (hasnm) - break; + if (n->type == ROFFT_TEXT && + n->string[0] == ',' && n->string[1] == '\0' && + n->next != NULL && n->next->tok == MDOC_Nm) { + n = n->next; + continue; + } /* FALLTHROUGH */ default: mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, n->line, n->pos, mdoc_macronames[n->tok]); - break; + continue; } + break; } if ( ! hasnm) diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 589983dd357..05591445668 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read.c,v 1.128 2016/12/28 17:21:17 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.129 2017/01/08 00:10:22 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -103,10 +103,11 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "no document body", "content before first section header", "first section is not \"NAME\"", - "NAME section without name", + "NAME section without Nm before Nd", "NAME section without description", "description not at the end of NAME", "bad NAME section content", + "missing comma before name", "missing description line, using \"\"", "sections out of conventional order", "duplicate section title", |