diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2011-10-24 21:41:45 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2011-10-24 21:41:45 +0000 |
commit | 6f4e3099b2c4764a55290af78c0a9ff3e00c1ecd (patch) | |
tree | f06b3042a55aef7236ae8bdf8090c51b542692d4 /roff.c | |
parent | 6cdd3db062dd695b8fc0c10cd2e58794757dfd95 (diff) | |
download | mandoc-6f4e3099b2c4764a55290af78c0a9ff3e00c1ecd.tar.gz |
Handle infinite recursion the same way as groff:
When string expansion exceeds the recursion limit, drop the whole
input line, instead of leaving just the string unexpanded.
ok kristaps@
Diffstat (limited to 'roff.c')
-rw-r--r-- | roff.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -186,7 +186,7 @@ static void roff_openeqn(struct roff *, const char *, int, int, const char *); static enum rofft roff_parse(struct roff *, const char *, int *); static enum rofferr roff_parsetext(char *); -static void roff_res(struct roff *, +static enum rofferr roff_res(struct roff *, char **, size_t *, int, int); static enum rofferr roff_rm(ROFF_ARGS); static void roff_setstr(struct roff *, @@ -432,7 +432,7 @@ roff_alloc(struct mparse *parse) * is processed. * This also checks the syntax of regular escapes. */ -static void +static enum rofferr roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos) { enum mandoc_esc esc; @@ -458,7 +458,7 @@ again: */ if ('\0' == *cp) - return; + return(ROFF_CONT); if ('*' != *cp) { res = cp; @@ -469,7 +469,7 @@ again: mandoc_msg (MANDOCERR_BADESCAPE, r->parse, ln, (int)(stesc - *bufp), NULL); - return; + return(ROFF_CONT); } cp++; @@ -482,7 +482,7 @@ again: switch (*cp) { case ('\0'): - return; + return(ROFF_CONT); case ('('): cp++; maxl = 2; @@ -505,7 +505,7 @@ again: (MANDOCERR_BADESCAPE, r->parse, ln, (int)(stesc - *bufp), NULL); - return; + return(ROFF_CONT); } if (0 == maxl && ']' == *cp) break; @@ -546,8 +546,9 @@ again: /* Just leave the string unexpanded. */ mandoc_msg(MANDOCERR_ROFFLOOP, r->parse, ln, pos, NULL); - return; + return(ROFF_IGN); } + return(ROFF_CONT); } /* @@ -604,7 +605,10 @@ roff_parseln(struct roff *r, int ln, char **bufp, * words to fill in. */ - roff_res(r, bufp, szp, ln, pos); + e = roff_res(r, bufp, szp, ln, pos); + if (ROFF_IGN == e) + return(e); + assert(ROFF_CONT == e); ppos = pos; ctl = mandoc_getcontrol(*bufp, &pos); |