summaryrefslogtreecommitdiffstats
path: root/term_ps.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-11-20 13:56:20 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-11-20 13:56:20 +0000
commitbbc2a36ee2ac85ca438a009fda76b29d2bf869d8 (patch)
tree10ec30c8b2b60b6fd6b7c9683356e1649ccd2e69 /term_ps.c
parent6a01104f8afa6637cdcab0bd214963902eac2eee (diff)
downloadmandoc-bbc2a36ee2ac85ca438a009fda76b29d2bf869d8.tar.gz
Prevent negative arguments to the .ll request from causing integer
underflow. Found while preparing an audit of termp.rmargin. Overflow can also happen, but i see no sane way to deal with it, so just let it happen. It doesn't happen for any sane input anyway, groff behaviour is undefined, and the resulting values are legal, even though they are useless.
Diffstat (limited to 'term_ps.c')
-rw-r--r--term_ps.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/term_ps.c b/term_ps.c
index f1129c2d..344db82f 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -635,12 +635,14 @@ ps_setwidth(struct termp *p, int iop, size_t width)
size_t lastwidth;
lastwidth = p->ps->width;
- if (0 < iop)
+ if (iop > 0)
p->ps->width += width;
- else if (0 > iop)
+ else if (iop == 0)
+ p->ps->width = width ? width : p->ps->lastwidth;
+ else if (p->ps->width > width)
p->ps->width -= width;
else
- p->ps->width = width ? width : p->ps->lastwidth;
+ p->ps->width = 0;
p->ps->lastwidth = lastwidth;
}