tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: roff.c question
Date: Sat, 4 Dec 2010 00:31:48 +0100	[thread overview]
Message-ID: <20101203233148.GC28384@iris.usta.de> (raw)
In-Reply-To: <20101202225019.GD12188@iris.usta.de>

Hi Kristaps,

>  2) We should implement some kind of stack limit
>     and just bail out.

OK to commit the following patch, too?

The constant of 1000 is the same that new groff is using,
and i'm mostly indifferent regarding the question which number
to use.


Note though that groff_char.man still puts a terrible strain on mandoc
even with these two patches:

  9219 lines of output, including
  1416 ERROR: input stack limit exceeded, infinite loop?
  3328 ERROR: skipping unknown macro
    10 other errors and warnings
  4465 lines of completely garbled output on stdout

On my old, slow test box, mandoc groff_char.man runs
more than two minutes with these two patches.

But i don't really see the point in trying to improve this.
We won't get anything even semi-sensible out of this input
without implementing full roff.

Yours,
  Ingo


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/main.c,v
retrieving revision 1.60
diff -u -p -r1.60 main.c
--- main.c	2 Dec 2010 20:40:43 -0000	1.60
+++ main.c	3 Dec 2010 23:19:01 -0000
@@ -162,6 +162,7 @@ static	const char * const	mandocerrs[MAN
 
 	"generic error",
 
+	"input stack limit exceeded, infinite loop?",
 	"skipping bad character",
 	"skipping text before the first section header",
 	"skipping unknown macro",
@@ -631,6 +632,8 @@ parsebuf(struct curparse *curp, struct b
 {
 	struct buf	 ln;
 	enum rofferr	 rr;
+	static int	 reparse_count;
+#define REPARSE_LIMIT	 1000
 	int		 i, of, rc;
 	int		 pos; /* byte number in the ln buffer */
 	int		 lnn; /* line number in the real file */
@@ -651,8 +654,10 @@ parsebuf(struct curparse *curp, struct b
 		if (0 == pos && '\0' == blk.buf[i])
 			break;
 
-		if (start)
+		if (start) {
 			curp->line = lnn;
+			reparse_count = 0;
+		}
 
 		while (i < (int)blk.sz && (start || '\0' != blk.buf[i])) {
 			if ('\n' == blk.buf[i]) {
@@ -751,7 +756,11 @@ rerun:
 
 		switch (rr) {
 		case (ROFF_REPARSE):
-			parsebuf(curp, ln, 0);
+			if (REPARSE_LIMIT >= ++reparse_count)
+				parsebuf(curp, ln, 0);
+			else
+				mmsg(MANDOCERR_ROFFLOOP, curp, 
+				    curp->line, pos, NULL);
 			pos = 0;
 			continue;
 		case (ROFF_APPEND):
Index: mandoc.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mandoc.h,v
retrieving revision 1.23
diff -u -p -r1.23 mandoc.h
--- mandoc.h	1 Dec 2010 22:02:29 -0000	1.23
+++ mandoc.h	3 Dec 2010 23:19:01 -0000
@@ -100,6 +100,7 @@ enum	mandocerr {
 	MANDOCERR_BADQUOTE, /* unterminated quoted string */
 
 	MANDOCERR_ERROR, /* ===== start of errors ===== */
+	MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
 	MANDOCERR_BADCHAR, /* skipping bad character */
 	MANDOCERR_NOTEXT, /* skipping text before the first section header */
 	MANDOCERR_MACRO, /* skipping unknown macro */
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

  parent reply	other threads:[~2010-12-03 23:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-01 16:33 exit_status persistence Kristaps Dzonsons
2010-12-01 16:41 ` Kristaps Dzonsons
2010-12-01 21:28 ` Ingo Schwarze
2010-12-02 10:51   ` exit_status persistence (now: roff.c question) Kristaps Dzonsons
2010-12-02 13:29     ` Kristaps Dzonsons
2010-12-02 22:50       ` roff.c question Ingo Schwarze
2010-12-03 21:49         ` Ingo Schwarze
2010-12-05 15:15           ` Kristaps Dzonsons
2010-12-08  1:05             ` Ingo Schwarze
2010-12-10  9:40               ` Kristaps Dzonsons
2010-12-10 20:45                 ` Ingo Schwarze
2010-12-10 20:52                   ` Joerg Sonnenberger
2010-12-10 21:10                     ` Ingo Schwarze
2010-12-10 21:17                       ` Joerg Sonnenberger
2010-12-10 23:12                       ` Ingo Schwarze
2010-12-03 23:31         ` Ingo Schwarze [this message]
2010-12-05 15:17           ` Kristaps Dzonsons
2010-12-09 23:45             ` Ingo Schwarze
2010-12-10  9:32               ` Kristaps Dzonsons
2010-12-02 20:54     ` Ingo Schwarze

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=20101203233148.GC28384@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.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).