From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: 1.11.7 regression: infinite loop in roff_res()
Date: Mon, 19 Sep 2011 01:34:15 +0200 [thread overview]
Message-ID: <20110918233415.GJ29692@iris.usta.de> (raw)
CVSROOT: /cvs
Module name: src
Changes by: schwarze@cvs.openbsd.org 2011/09/18 17:26:18
Modified files:
usr.bin/mandoc : roff.c
Log message:
Fix another regression introduced in 1.11.7:
If a string is defined in terms of itself, the REPARSE_LIMIT in read.c
used to break the cycle. This no longer works since all the work
is now done in the function roff_res(), looping indefinitely.
Make this loop finite by arbitrarily limiting the number of times one
string may be expanded; when that limit is reached, leave the remaining
string references unexpanded.
This changes behaviour compared to 1.11.5, where the whole line would
have been dropped. The new behaviour is better because it loses less
information. We don't want to imitate groff-1.20.1 behaviour anyway
because groff aborts parsing of the whole file.
OK to commit to bsd.lv as well?
Ingo
Index: roff.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/roff.c,v
retrieving revision 1.42
diff -u -p -r1.42 roff.c
--- roff.c 18 Sep 2011 15:54:48 -0000 1.42
+++ roff.c 18 Sep 2011 23:01:05 -0000
@@ -27,6 +27,9 @@
/* Maximum number of nested if-else conditionals. */
#define RSTACK_MAX 128
+/* Maximum number of string expansions per line, to break infinite loops. */
+#define EXPAND_LIMIT 1000
+
enum rofft {
ROFF_ad,
ROFF_am,
@@ -433,10 +436,12 @@ roff_res(struct roff *r, char **bufp, si
const char *stnam; /* start of the name, after "[(*" */
const char *cp; /* end of the name, e.g. before ']' */
const char *res; /* the string to be substituted */
- int i, maxl;
+ int i, maxl, expand_count;
size_t nsz;
char *n;
+ expand_count = 0;
+
again:
cp = *bufp + pos;
while (NULL != (cp = strchr(cp, '\\'))) {
@@ -531,7 +536,13 @@ again:
*bufp = n;
*szp = nsz;
- goto again;
+
+ if (EXPAND_LIMIT >= ++expand_count)
+ goto again;
+
+ /* Just leave the string unexpanded. */
+ mandoc_msg(MANDOCERR_ROFFLOOP, r->parse, ln, pos, NULL);
+ return;
}
}
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next reply other threads:[~2011-09-18 23:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-18 23:34 Ingo Schwarze [this message]
2011-09-18 23:46 ` Kristaps Dzonsons
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=20110918233415.GJ29692@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).