=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.244 retrieving revision 1.245 diff -u -p -r1.244 -r1.245 --- mandoc/roff.c 2014/12/18 17:43:41 1.244 +++ mandoc/roff.c 2014/12/25 17:23:32 1.245 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.244 2014/12/18 17:43:41 schwarze Exp $ */ +/* $Id: roff.c,v 1.245 2014/12/25 17:23:32 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 @@ -657,6 +658,12 @@ roff_res(struct roff *r, struct buf *buf, int ln, int *stesc = '\0'; buf->sz = mandoc_asprintf(&nbuf, "%s%s%s", buf->buf, res, cp) + 1; + + if (buf->sz > SHRT_MAX) { + mandoc_msg(MANDOCERR_ROFFLOOP, r->parse, + ln, (int)(stesc - buf->buf), NULL); + return(ROFF_IGN); + } /* Prepare for the next replacement. */