source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: The syntax of the roff(7) .mc request is quite special and the
Date: Thu, 28 Apr 2022 11:21:42 -0500 (EST)	[thread overview]
Message-ID: <33651a0aff4e08d1@mandoc.bsd.lv> (raw)

Log Message:
-----------
The syntax of the roff(7) .mc request is quite special
and the roff_onearg() parsing function is too generic,
so provide a dedicated parsing function instead.

This fixes an assertion failure when an \o escape sequence is
passed as the argument; the bug was found by tb@ using afl(1).
It also makes mandoc output more similar to groff in various cases.

Modified Files:
--------------
    mandoc:
        mandoc.1
        mandoc.h
        mandoc_msg.c
        roff.c
    mandoc/regress/roff:
        Makefile

Added Files:
-----------
    mandoc/regress/roff/mc:
        Makefile
        args.in
        args.out_ascii
        args.out_lint

Revision Data
-------------
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/roff/Makefile,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lregress/roff/Makefile -Lregress/roff/Makefile -u -p -r1.9 -r1.10
--- regress/roff/Makefile
+++ regress/roff/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.28 2019/01/04 01:06:44 schwarze Exp $
+# $OpenBSD: Makefile,v 1.29 2022/04/28 16:16:46 schwarze Exp $
 
 SUBDIR  = args cond esc scale string
-SUBDIR += br cc ce char de ds ft ig it ll na nr po ps
+SUBDIR += br cc ce char de ds ft ig it ll mc na nr po ps
 SUBDIR += return rm rn shift sp ta ti tr while
 
 .include "../Makefile.sub"
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.383
retrieving revision 1.384
diff -Lroff.c -Lroff.c -u -p -r1.383 -r1.384
--- roff.c
+++ roff.c
@@ -227,6 +227,7 @@ static	int		 roff_line_ignore(ROFF_ARGS)
 static	void		 roff_man_alloc1(struct roff_man *);
 static	void		 roff_man_free1(struct roff_man *);
 static	int		 roff_manyarg(ROFF_ARGS);
+static	int		 roff_mc(ROFF_ARGS);
 static	int		 roff_noarg(ROFF_ARGS);
 static	int		 roff_nop(ROFF_ARGS);
 static	int		 roff_nr(ROFF_ARGS);
@@ -379,7 +380,7 @@ static	struct roffmac	 roffs[TOKEN_NONE]
 	{ roff_noarg, NULL, NULL, 0 },  /* fi */
 	{ roff_onearg, NULL, NULL, 0 },  /* ft */
 	{ roff_onearg, NULL, NULL, 0 },  /* ll */
-	{ roff_onearg, NULL, NULL, 0 },  /* mc */
+	{ roff_mc, NULL, NULL, 0 },  /* mc */
 	{ roff_noarg, NULL, NULL, 0 },  /* nf */
 	{ roff_onearg, NULL, NULL, 0 },  /* po */
 	{ roff_onearg, NULL, NULL, 0 },  /* rj */
@@ -3728,6 +3729,54 @@ roff_eo(ROFF_ARGS)
 	if (buf->buf[pos] != '\0')
 		mandoc_msg(MANDOCERR_ARG_SKIP,
 		    ln, pos, "eo %s", buf->buf + pos);
+	return ROFF_IGN;
+}
+
+static int
+roff_mc(ROFF_ARGS)
+{
+	struct roff_node	*n;
+	char			*cp;
+
+	/* Parse the first argument. */
+
+	cp = buf->buf + pos;
+	if (*cp != '\0')
+		cp++;
+	if (buf->buf[pos] == '\\') {
+		switch (mandoc_escape((const char **)&cp, NULL, NULL)) {
+		case ESCAPE_SPECIAL:
+		case ESCAPE_UNICODE:
+		case ESCAPE_NUMBERED:
+			break;
+		default:
+			*cp = '\0';
+			mandoc_msg(MANDOCERR_MC_ESC, ln, pos,
+			    "mc %s", buf->buf + pos);
+			buf->buf[pos] = '\0';
+			break;
+		}
+	}
+
+	/* Ignore additional arguments. */
+
+	while (*cp == ' ')
+		*cp++ = '\0';
+	if (*cp != '\0') {
+		mandoc_msg(MANDOCERR_MC_DIST, ln, (int)(cp - buf->buf),
+		    "mc ... %s", cp);
+		*cp = '\0';
+	}
+
+	/* Create the .mc node. */
+
+	roff_elem_alloc(r->man, ln, ppos, tok);
+	n = r->man->last;
+	if (buf->buf[pos] != '\0')
+		roff_word_alloc(r->man, ln, pos, buf->buf + pos);
+	n->flags |= NODE_LINE | NODE_VALID | NODE_ENDED;
+	r->man->last = n;
+	r->man->next = ROFF_NEXT_SIBLING;
 	return ROFF_IGN;
 }
 
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.h,v
retrieving revision 1.275
retrieving revision 1.276
diff -Lmandoc.h -Lmandoc.h -u -p -r1.275 -r1.276
--- mandoc.h
+++ mandoc.h
@@ -165,6 +165,7 @@ enum	mandocerr {
 	MANDOCERR_SM_BAD, /* invalid Boolean argument: macro arg */
 	MANDOCERR_CHAR_FONT, /* argument contains two font escapes */
 	MANDOCERR_FT_BAD, /* unknown font, skipping request: ft font */
+	MANDOCERR_MC_DIST, /* ignoring distance argument: mc ... arg */
 	MANDOCERR_TR_ODD, /* odd number of characters in request: tr char */
 
 	/* related to plain text */
@@ -221,6 +222,7 @@ enum	mandocerr {
 	MANDOCERR_BL_NOTYPE, /* missing list type, using -item: Bl */
 	MANDOCERR_CE_NONUM, /* argument is not numeric, using 1: ce ... */
 	MANDOCERR_CHAR_ARG, /* argument is not a character: char ... */
+	MANDOCERR_MC_ESC, /* skipping unusable escape sequence: mc arg */
 	MANDOCERR_NM_NONAME, /* missing manual name, using "": Nm */
 	MANDOCERR_OS_UNAME, /* uname(3) system call failed, using UNKNOWN */
 	MANDOCERR_ST_BAD, /* unknown standard specifier: St standard */
Index: mandoc_msg.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_msg.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lmandoc_msg.c -Lmandoc_msg.c -u -p -r1.17 -r1.18
--- mandoc_msg.c
+++ mandoc_msg.c
@@ -166,6 +166,7 @@ static	const char *const type_message[MA
 	"invalid Boolean argument",
 	"argument contains two font escapes",
 	"unknown font, skipping request",
+	"ignoring distance argument",
 	"odd number of characters in request",
 
 	/* related to plain text */
@@ -222,6 +223,7 @@ static	const char *const type_message[MA
 	"missing list type, using -item",
 	"argument is not numeric, using 1",
 	"argument is not a character",
+	"skipping unusable escape sequence",
 	"missing manual name, using \"\"",
 	"uname(3) system call failed, using UNKNOWN",
 	"unknown standard specifier",
Index: mandoc.1
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.1,v
retrieving revision 1.257
retrieving revision 1.258
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.257 -r1.258
--- mandoc.1
+++ mandoc.1
@@ -1754,6 +1754,15 @@ request or a
 layout modifier has an unknown
 .Ar font
 argument.
+.It Sy "ignoring distance argument"
+.Pq roff
+In addition to the margin character, an
+.Ic \&mc
+request has a second argument supposed to represent a distance, but the
+.Nm
+implementation of
+.Ic \&mc
+always ignores the second argument.
 .It Sy "odd number of characters in request"
 .Pq roff
 A
@@ -2124,6 +2133,13 @@ The first argument of a
 request is neither a single ASCII character
 nor a single character escape sequence.
 The request is ignored including all its arguments.
+.It Sy "skipping unusable escape sequence"
+.Pq roff
+The first argument of an
+.Ic mc
+request is neither a single ASCII character
+nor a single character escape sequence.
+All arguments are ignored and printing of a margin character is disabled.
 .It Sy "missing manual name, using \(dq\(dq"
 .Pq mdoc
 The first call to
--- /dev/null
+++ regress/roff/mc/args.out_ascii
@@ -0,0 +1,19 @@
+MC-ARGS(1)                  General Commands Manual                 MC-ARGS(1)
+
+N\bNA\bAM\bME\bE
+       mc-args - arguments to the .mc request
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       initial text
+       ASCII character in the margin               |
+       invalid escape sequence
+       unsupported escape sequence
+       ignored escape sequence
+       special character in the margin             |
+       special character represented as string     <integral>
+       font escape in the margin
+       numbered character in the margin            |
+       Unicode character in the margin             |
+       overstriking in the margin
+
+OpenBSD                         April 28, 2022                      MC-ARGS(1)
--- /dev/null
+++ regress/roff/mc/args.in
@@ -0,0 +1,29 @@
+.\" $OpenBSD: args.in,v 1.1 2022/04/28 16:16:46 schwarze Exp $
+.TH MC-ARGS 1 "April 28, 2022"
+.SH NAME
+mc-args \- arguments to the .mc request
+.SH DESCRIPTION
+.ll 50n
+.nf
+initial text
+.mc |suffix
+ASCII character in the margin
+.mc \CXX
+invalid escape sequence
+.mc \!
+unsupported escape sequence
+.mc \a
+ignored escape sequence
+.mc \(ba
+special character in the margin
+.mc \[integral]
+special character represented as string
+.mc \fR
+font escape in the margin
+.mc \N'124'
+numbered character in the margin
+.mc \[u007C]suffix
+Unicode character in the margin
+.mc \o'o/'
+overstriking in the margin
+.ll
--- /dev/null
+++ regress/roff/mc/Makefile
@@ -0,0 +1,6 @@
+# $OpenBSD: Makefile,v 1.1 2022/04/28 16:16:46 schwarze Exp $
+
+REGRESS_TARGETS	 = args
+LINT_TARGETS	 = args
+
+.include <bsd.regress.mk>
--- /dev/null
+++ regress/roff/mc/args.out_lint
@@ -0,0 +1,9 @@
+mandoc: args.in:9:6: WARNING: ignoring distance argument: mc ... suffix
+mandoc: args.in:11:5: WARNING: invalid escape sequence: \C
+mandoc: args.in:11:5: ERROR: skipping unusable escape sequence: mc \C
+mandoc: args.in:13:5: UNSUPP: unsupported escape sequence: \!
+mandoc: args.in:13:5: ERROR: skipping unusable escape sequence: mc \!
+mandoc: args.in:15:5: ERROR: skipping unusable escape sequence: mc \a
+mandoc: args.in:21:5: ERROR: skipping unusable escape sequence: mc \fR
+mandoc: args.in:25:13: WARNING: ignoring distance argument: mc ... suffix
+mandoc: args.in:27:5: ERROR: skipping unusable escape sequence: mc \o'o/'
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


                 reply	other threads:[~2022-04-28 16:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33651a0aff4e08d1@mandoc.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).