diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2020-09-03 17:37:07 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2020-09-03 17:37:07 +0000 |
commit | e4e5a6cd323c6b8c720b412abfa7dba9b308b5f8 (patch) | |
tree | 11daf30cf0ac4cbf1c8759e04e11e9196eabca8b /usr.bin/mandoc/roff_term.c | |
parent | b177345935d57471bfc2d8d73ac2c91d36dcc9a1 (diff) |
If .ti had an excessive argument, using it was attempted, in some
cases resulting in an assertion failure. Instead, truncate the
temporary indent to a width reasonable in a manual page.
I found the issue in an afl run
that was performed by Jan Schreiber <jes at posteo dot de>.
Diffstat (limited to 'usr.bin/mandoc/roff_term.c')
-rw-r--r-- | usr.bin/mandoc/roff_term.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/usr.bin/mandoc/roff_term.c b/usr.bin/mandoc/roff_term.c index ef90623538e..dc4d4d81bc7 100644 --- a/usr.bin/mandoc/roff_term.c +++ b/usr.bin/mandoc/roff_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff_term.c,v 1.19 2019/01/04 03:24:30 schwarze Exp $ */ +/* $OpenBSD: roff_term.c,v 1.20 2020/09/03 17:37:06 schwarze Exp $ */ /* * Copyright (c) 2010,2014,2015,2017-2019 Ingo Schwarze <schwarze@openbsd.org> * @@ -208,6 +208,7 @@ roff_term_pre_ti(ROFF_TERM_ARGS) { struct roffsu su; const char *cp; + const size_t maxoff = 72; int len, sign; roff_term_pre_br(p, n); @@ -228,17 +229,26 @@ roff_term_pre_ti(ROFF_TERM_ARGS) return; len = term_hen(p, &su); - if (sign == 0) { + switch (sign) { + case 1: + if (p->tcol->offset + len <= maxoff) + p->ti = len; + else if (p->tcol->offset < maxoff) + p->ti = maxoff - p->tcol->offset; + else + p->ti = 0; + break; + case -1: + if ((size_t)len < p->tcol->offset) + p->ti = -len; + else + p->ti = -p->tcol->offset; + break; + default: + if ((size_t)len > maxoff) + len = maxoff; p->ti = len - p->tcol->offset; - p->tcol->offset = len; - } else if (sign == 1) { - p->ti = len; - p->tcol->offset += len; - } else if ((size_t)len < p->tcol->offset) { - p->ti = -len; - p->tcol->offset -= len; - } else { - p->ti = -p->tcol->offset; - p->tcol->offset = 0; + break; } + p->tcol->offset += p->ti; } |