diff options
author | 2015-01-31 00:11:51 +0000 | |
---|---|---|
committer | 2015-01-31 00:11:51 +0000 | |
commit | f29a1da1c76d10248092dd04d948d8ca66c440ce (patch) | |
tree | 15284989ad97012cec733acddecd423285490baf | |
parent | Fix mbuf leak in Linux compat setsockopt() in the error path when (diff) | |
download | wireguard-openbsd-f29a1da1c76d10248092dd04d948d8ca66c440ce.tar.xz wireguard-openbsd-f29a1da1c76d10248092dd04d948d8ca66c440ce.zip |
Use relative offsets instead of absolute pointers for the terminal
font stack. The latter fail after the stack is grown with realloc().
Fixing an assertion failure found by jsg@ with afl some time ago
(test case number 51).
-rw-r--r-- | usr.bin/mandoc/mdoc.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_term.c | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/term.h | 5 |
5 files changed, 16 insertions, 25 deletions
diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index 24c257935c9..a4a7f9df810 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc.h,v 1.58 2014/12/18 03:09:42 schwarze Exp $ */ +/* $OpenBSD: mdoc.h,v 1.59 2015/01/31 00:11:51 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -366,7 +366,7 @@ struct mdoc_node { enum mdoc_type type; /* AST node type */ enum mdoc_sec sec; /* current named section */ union mdoc_data *norm; /* normalised args */ - const void *prev_font; /* before entering this node */ + int prev_font; /* before entering this node */ /* FIXME: these can be union'd to shave a few bytes. */ struct mdoc_arg *args; /* BLOCK/ELEM */ struct mdoc_node *pending; /* BLOCK */ diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 3e8942f2480..d8ed3ec7536 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.203 2015/01/30 22:04:15 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.204 2015/01/31 00:11:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -305,7 +305,7 @@ print_mdoc_node(DECL_ARGS) chld = 1; offset = p->offset; rmargin = p->rmargin; - n->prev_font = term_fontq(p); + n->prev_font = p->fonti; memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c index 40b24a63439..afad57d7074 100644 --- a/usr.bin/mandoc/tbl_term.c +++ b/usr.bin/mandoc/tbl_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_term.c,v 1.25 2015/01/30 17:31:20 schwarze Exp $ */ +/* $OpenBSD: tbl_term.c,v 1.26 2015/01/31 00:11:52 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -412,9 +412,9 @@ tbl_number(struct termp *tp, const struct tbl_opts *opts, static void tbl_word(struct termp *tp, const struct tbl_dat *dp) { - const void *prev_font; + int prev_font; - prev_font = term_fontq(tp); + prev_font = tp->fonti; if (dp->layout->flags & TBL_CELL_BOLD) term_fontpush(tp, TERMFONT_BOLD); else if (dp->layout->flags & TBL_CELL_ITALIC) diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index 74401b36739..88834e24d7d 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.103 2015/01/21 20:20:49 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.104 2015/01/31 00:11:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -361,22 +361,14 @@ term_fontpush(struct termp *p, enum termfont f) p->fontq[p->fonti] = f; } -/* Retrieve pointer to current font. */ -const enum termfont * -term_fontq(struct termp *p) -{ - - return(&p->fontq[p->fonti]); -} - /* Flush to make the saved pointer current again. */ void -term_fontpopq(struct termp *p, const enum termfont *key) +term_fontpopq(struct termp *p, int i) { - while (p->fonti >= 0 && key < p->fontq + p->fonti) - p->fonti--; - assert(p->fonti >= 0); + assert(i >= 0); + if (p->fonti > i) + p->fonti = i; } /* Pop one font off the stack. */ @@ -566,7 +558,7 @@ encode1(struct termp *p, int c) if (p->col + 6 >= p->maxcols) adjbuf(p, p->col + 6); - f = *term_fontq(p); + f = p->fontq[p->fonti]; if (TERMFONT_UNDER == f || TERMFONT_BI == f) { p->buf[p->col++] = '_'; @@ -598,7 +590,7 @@ encode(struct termp *p, const char *word, size_t sz) * character by character. */ - if (*term_fontq(p) == TERMFONT_NONE) { + if (p->fontq[p->fonti] == TERMFONT_NONE) { if (p->col + sz >= p->maxcols) adjbuf(p, p->col + sz); for (i = 0; i < sz; i++) diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h index 2bb97aa7d37..35fe140277c 100644 --- a/usr.bin/mandoc/term.h +++ b/usr.bin/mandoc/term.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term.h,v 1.54 2014/12/23 13:48:15 schwarze Exp $ */ +/* $OpenBSD: term.h,v 1.55 2015/01/31 00:11:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -126,10 +126,9 @@ int term_vspan(const struct termp *, const struct roffsu *); size_t term_strlen(const struct termp *, const char *); size_t term_len(const struct termp *, size_t); -const enum termfont *term_fontq(struct termp *); void term_fontpush(struct termp *, enum termfont); void term_fontpop(struct termp *); -void term_fontpopq(struct termp *, const enum termfont *); +void term_fontpopq(struct termp *, int); void term_fontrepl(struct termp *, enum termfont); void term_fontlast(struct termp *); |