From 4a5cf76e05bfa8c6f11863146fd01fe30a12eb82 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 8 Jan 2017 00:11:23 +0000 Subject: 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 --- mandoc.1 | 21 ++++++++++++++------- mandoc.h | 7 ++++--- mdoc_validate.c | 30 +++++++++++++++++++----------- read.c | 7 ++++--- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/mandoc.1 b/mandoc.1 index 435ed84e..98457b2f 100644 --- a/mandoc.1 +++ b/mandoc.1 @@ -1,7 +1,7 @@ -.\" $Id: mandoc.1,v 1.167 2017/01/06 01:34:57 schwarze Exp $ +.\" $Id: mandoc.1,v 1.168 2017/01/08 00:11:23 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons -.\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze +.\" Copyright (c) 2012, 2014-2017 Ingo Schwarze .\" .\" 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/mandoc.h b/mandoc.h index 448a3e04..89458d39 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,7 +1,7 @@ -/* $Id: mandoc.h,v 1.211 2016/12/28 17:34:18 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.212 2017/01/08 00:11:23 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons - * Copyright (c) 2010-2016 Ingo Schwarze + * Copyright (c) 2010-2017 Ingo Schwarze * * 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/mdoc_validate.c b/mdoc_validate.c index 504acd87..89969d63 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,7 +1,7 @@ -/* $Id: mdoc_validate.c,v 1.310 2016/12/28 17:34:18 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.311 2017/01/08 00:11:24 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2016 Ingo Schwarze + * Copyright (c) 2010-2017 Ingo Schwarze * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -851,12 +851,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"); } @@ -1598,8 +1597,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) @@ -1607,14 +1610,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/read.c b/read.c index 1ebc7500..54cc8530 100644 --- a/read.c +++ b/read.c @@ -1,7 +1,7 @@ -/* $Id: read.c,v 1.155 2016/12/28 17:34:18 schwarze Exp $ */ +/* $Id: read.c,v 1.156 2017/01/08 00:11:24 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010-2016 Ingo Schwarze + * Copyright (c) 2010-2017 Ingo Schwarze * Copyright (c) 2010, 2012 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -108,10 +108,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", -- cgit v1.2.3-56-ge451