From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id oB3NVpgV019211 for ; Fri, 3 Dec 2010 18:31:52 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1POf6S-0006Br-OD; Sat, 04 Dec 2010 00:31:50 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1POf6S-0007Vj-Md for tech@mdocml.bsd.lv; Sat, 04 Dec 2010 00:31:48 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1POf6S-0007aO-Lb for tech@mdocml.bsd.lv; Sat, 04 Dec 2010 00:31:48 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1POf6S-0003Mi-Kt for tech@mdocml.bsd.lv; Sat, 04 Dec 2010 00:31:48 +0100 Date: Sat, 4 Dec 2010 00:31:48 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: Re: roff.c question Message-ID: <20101203233148.GC28384@iris.usta.de> References: <4CF678F0.6020304@bsd.lv> <20101201212834.GA22990@iris.usta.de> <4CF77A2B.6020702@bsd.lv> <4CF79F45.6080105@bsd.lv> <20101202225019.GD12188@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101202225019.GD12188@iris.usta.de> User-Agent: Mutt/1.5.21 (2010-09-15) 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