=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.243 retrieving revision 1.246 diff -u -p -r1.243 -r1.246 --- mandoc/roff.c 2014/12/16 23:44:41 1.243 +++ mandoc/roff.c 2014/12/28 14:16:26 1.246 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.243 2014/12/16 23:44:41 schwarze Exp $ */ +/* $Id: roff.c,v 1.246 2014/12/28 14:16:26 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -650,6 +651,10 @@ roff_res(struct roff *r, struct buf *buf, int ln, int r->parse, ln, (int)(stesc - buf->buf), "%.*s", (int)naml, stnam); res = ""; + } else if (buf->sz + strlen(res) > SHRT_MAX) { + mandoc_msg(MANDOCERR_ROFFLOOP, r->parse, + ln, (int)(stesc - buf->buf), NULL); + return(ROFF_IGN); } /* Replace the escape sequence by the string. */ @@ -1576,7 +1581,7 @@ roff_evalnum(struct roff *r, int ln, const char *v, *res *= operand2; break; case '/': - if (0 == operand2) { + if (operand2 == 0) { mandoc_msg(MANDOCERR_DIVZERO, r->parse, ln, *pos, v); *res = 0; @@ -1585,6 +1590,12 @@ roff_evalnum(struct roff *r, int ln, const char *v, *res /= operand2; break; case '%': + if (operand2 == 0) { + mandoc_msg(MANDOCERR_DIVZERO, + r->parse, ln, *pos, v); + *res = 0; + break; + } *res %= operand2; break; case '<':