source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Ignore unreasonably large spacing modifiers in tbl layouts.
Date: Tue, 1 Sep 2020 13:25:31 -0500 (EST)	[thread overview]
Message-ID: <f200d32c1c453d62@mandoc.bsd.lv> (raw)

Log Message:
-----------
Ignore unreasonably large spacing modifiers in tbl layouts.

Jan Schreiber <jes at posteo dot de> ran afl on mandoc and it turned
out mandoc tried to use spacing modifiers so large that they would
trigger assertion failures in term_ascii.c, function locale_advance().

Modified Files:
--------------
    mandoc:
        mandoc.1
        mandoc.h
        mandoc_msg.c
        tbl_layout.c
    mandoc/regress/tbl/layout:
        Makefile

Added Files:
-----------
    mandoc/regress/tbl/layout:
        spacing-nogroff.in
        spacing-nogroff.out_ascii
        spacing-nogroff.out_lint
        spacing.in
        spacing.out_ascii

Revision Data
-------------
Index: mandoc.1
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.1,v
retrieving revision 1.247
retrieving revision 1.248
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.247 -r1.248
--- mandoc.1
+++ mandoc.1
@@ -1850,6 +1850,10 @@ The invalid character is discarded.
 A table layout specification contains an opening parenthesis,
 but no matching closing parenthesis.
 The rest of the input line, starting from the parenthesis, has no effect.
+.It Sy "ignoring excessive spacing in tbl layout"
+.Pq tbl
+A spacing modifier in a table layout is unreasonably large.
+The default spacing of 3n is used instead.
 .It Sy "tbl without any data cells"
 .Pq tbl
 A table does not contain any data cells.
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.h,v
retrieving revision 1.268
retrieving revision 1.269
diff -Lmandoc.h -Lmandoc.h -u -p -r1.268 -r1.269
--- mandoc.h
+++ mandoc.h
@@ -189,6 +189,7 @@ enum	mandocerr {
 	MANDOCERR_TBLLAYOUT_NONE, /* empty tbl layout */
 	MANDOCERR_TBLLAYOUT_CHAR, /* invalid character in tbl layout: char */
 	MANDOCERR_TBLLAYOUT_PAR, /* unmatched parenthesis in tbl layout */
+	MANDOCERR_TBLLAYOUT_SPC, /* ignoring excessive spacing in tbl layout */
 	MANDOCERR_TBLDATA_NONE, /* tbl without any data cells */
 	MANDOCERR_TBLDATA_SPAN, /* ignoring data in spanned tbl cell: data */
 	MANDOCERR_TBLDATA_EXTRA, /* ignoring extra tbl data cells: data */
Index: mandoc_msg.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_msg.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lmandoc_msg.c -Lmandoc_msg.c -u -p -r1.11 -r1.12
--- mandoc_msg.c
+++ mandoc_msg.c
@@ -190,6 +190,7 @@ static	const char *const type_message[MA
 	"empty tbl layout",
 	"invalid character in tbl layout",
 	"unmatched parenthesis in tbl layout",
+	"ignoring excessive spacing in tbl layout",
 	"tbl without any data cells",
 	"ignoring data in spanned tbl cell",
 	"ignoring extra tbl data cells",
Index: tbl_layout.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tbl_layout.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -Ltbl_layout.c -Ltbl_layout.c -u -p -r1.48 -r1.49
--- tbl_layout.c
+++ tbl_layout.c
@@ -65,6 +65,7 @@ mods(struct tbl_node *tbl, struct tbl_ce
 		int ln, const char *p, int *pos)
 {
 	char		*endptr;
+	unsigned long	 spacing;
 	size_t		 sz;
 
 mod:
@@ -93,7 +94,11 @@ mod:
 	/* Parse numerical spacing from modifier string. */
 
 	if (isdigit((unsigned char)p[*pos])) {
-		cp->spacing = strtoull(p + *pos, &endptr, 10);
+		if ((spacing = strtoul(p + *pos, &endptr, 10)) > 9)
+			mandoc_msg(MANDOCERR_TBLLAYOUT_SPC, ln, *pos,
+			    "%lu", spacing);
+		else
+			cp->spacing = spacing;
 		*pos = endptr - p;
 		goto mod;
 	}
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/tbl/layout/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lregress/tbl/layout/Makefile -Lregress/tbl/layout/Makefile -u -p -r1.5 -r1.6
--- regress/tbl/layout/Makefile
+++ regress/tbl/layout/Makefile
@@ -1,15 +1,17 @@
 # $OpenBSD: Makefile,v 1.6 2020/01/11 20:56:26 schwarze Exp $
 
 REGRESS_TARGETS	 = badspan center complex empty emptycol emptyline
-REGRESS_TARGETS	+= lines lines-nogroff numbers shortlines span
-LINT_TARGETS	 = badspan complex empty
+REGRESS_TARGETS	+= lines lines-nogroff numbers
+REGRESS_TARGETS	+= shortlines spacing spacing-nogroff span
+LINT_TARGETS	 = badspan complex empty spacing-nogroff
 
-# groff-1.22.3 defects:
+# groff-1.22.4 defects:
 # - When the layout is completely empty,
 #   GNU eqn produces no output whatsoever for the whole table.
 # - When there is no horizontal line at the top,
 #   vertical lines extend beyond the top of the table.
+# - Excessive spacing modifiers in the layout are honoured.
 
-SKIP_GROFF	 = empty lines-nogroff
+SKIP_GROFF	 = empty lines-nogroff spacing-nogroff
 
 .include <bsd.regress.mk>
--- /dev/null
+++ regress/tbl/layout/spacing.out_ascii
@@ -0,0 +1,39 @@
+TBL-LAYOUT-SPACING(1)       General Commands Manual      TBL-LAYOUT-SPACING(1)
+
+
+
+N\bNA\bAM\bME\bE
+       tbl-layout-spacing - spacing modifiers
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       default spacing:
+
+       +------+
+       |a   b |
+       +------+
+       spacing 0:
+
+       +---+
+       |ab |
+       +---+
+       spacing 1:
+
+       +----+
+       |a b |
+       +----+
+       spacing 2:
+
+       +--+--+
+       |a |b |
+       +--+--+
+       spacing 5:
+
+       +---++---+
+       |a  || b |
+       +---++---+
+       leaked tab settings:
+       a b     cdef
+
+
+
+OpenBSD                        September 1, 2020         TBL-LAYOUT-SPACING(1)
--- /dev/null
+++ regress/tbl/layout/spacing-nogroff.in
@@ -0,0 +1,13 @@
+.\" $OpenBSD$
+.TH TBL-LAYOUT-SPACING 1 "September 1, 2020"
+.SH NAME
+tbl-layout-spacing-nogroff \- excessive spacing modifier
+.SH DESCRIPTION
+initial text
+.TS
+box tab(:);
+R 10 L.
+a:b
+.TE
+.sp
+final text
--- /dev/null
+++ regress/tbl/layout/spacing-nogroff.out_ascii
@@ -0,0 +1,18 @@
+TBL-LAYOUT-SPACING(1)       General Commands Manual      TBL-LAYOUT-SPACING(1)
+
+
+
+N\bNA\bAM\bME\bE
+       tbl-layout-spacing-nogroff - excessive spacing modifier
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       initial text
+
+       +------+
+       |a   b |
+       +------+
+       final text
+
+
+
+OpenBSD                        September 1, 2020         TBL-LAYOUT-SPACING(1)
--- /dev/null
+++ regress/tbl/layout/spacing.in
@@ -0,0 +1,43 @@
+.\" $OpenBSD$
+.TH TBL-LAYOUT-SPACING 1 "September 1, 2020"
+.SH NAME
+tbl-layout-spacing \- spacing modifiers
+.SH DESCRIPTION
+default spacing:
+.TS
+box tab(:);
+R L.
+a:b
+.TE
+.sp
+spacing 0:
+.TS
+box tab(:);
+R 0 L.
+a:b
+.TE
+.sp
+spacing 1:
+.TS
+box tab(:);
+R 1 L.
+a:b
+.TE
+.sp
+spacing 2:
+.TS
+allbox tab(:);
+R 2 L.
+a:b
+.TE
+.sp
+spacing 5:
+.TS
+allbox tab(:);
+R 5|| L.
+a:b
+.TE
+.sp
+leaked tab settings:
+.br
+a	b	c	d	e	f
--- /dev/null
+++ regress/tbl/layout/spacing-nogroff.out_lint
@@ -0,0 +1 @@
+mandoc: spacing-nogroff.in:9:3: ERROR: ignoring excessive spacing in tbl layout: 10
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


                 reply	other threads:[~2020-09-01 18:25 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=f200d32c1c453d62@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).