summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2018-05-20 21:37:11 +0000
committerschwarze <schwarze@openbsd.org>2018-05-20 21:37:11 +0000
commitfe245e6ac992789334cb484c31f88d1b635e8080 (patch)
tree28b5c0e0ffa22640347a091241e53ee2b638aab8
parenttipmic(4) (diff)
downloadwireguard-openbsd-fe245e6ac992789334cb484c31f88d1b635e8080.tar.xz
wireguard-openbsd-fe245e6ac992789334cb484c31f88d1b635e8080.zip
Protect against malicious manual pages containing .ll requests with
excessive arguments: apply the same cutoff as for the -O width= command line argument. While here, also place some assertions at strategical places to prevent excessive indentations from being printed in case of bugs. In the past, we had more than one bug that caused mandoc to print effectively infinite output, filling up people's /tmp/ file system, which is not funny. We cannot prevent bugs from crashing the program, but we can at least make filling up the disk less likely. Triggered by a remark from sthen@ on source-changes@.
-rw-r--r--usr.bin/mandoc/term_ascii.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/usr.bin/mandoc/term_ascii.c b/usr.bin/mandoc/term_ascii.c
index c59159b69f0..3e4eacca34d 100644
--- a/usr.bin/mandoc/term_ascii.c
+++ b/usr.bin/mandoc/term_ascii.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: term_ascii.c,v 1.45 2018/04/13 18:29:19 schwarze Exp $ */
+/* $OpenBSD: term_ascii.c,v 1.46 2018/05/20 21:37:11 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -121,6 +121,8 @@ ascii_init(enum termenc enc, const struct manoutput *outopts)
if (outopts->synopsisonly)
p->synopsisonly = 1;
+ assert(p->defindent < UINT16_MAX);
+ assert(p->defrmargin < UINT16_MAX);
return p;
}
@@ -159,6 +161,8 @@ ascii_setwidth(struct termp *p, int iop, int width)
p->defrmargin -= width;
else
p->defrmargin = 0;
+ if (p->defrmargin > 1000)
+ p->defrmargin = 1000;
p->lastrmargin = p->tcol->rmargin;
p->tcol->rmargin = p->maxrmargin = p->defrmargin;
}
@@ -227,6 +231,7 @@ ascii_advance(struct termp *p, size_t len)
{
size_t i;
+ assert(len < UINT16_MAX);
for (i = 0; i < len; i++)
putchar(' ');
}
@@ -363,6 +368,7 @@ locale_advance(struct termp *p, size_t len)
{
size_t i;
+ assert(len < UINT16_MAX);
for (i = 0; i < len; i++)
putwchar(L' ');
}