summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-11-28 16:02:23 +0000
committerschwarze <schwarze@openbsd.org>2014-11-28 16:02:23 +0000
commita19c2534b4be3829735c8863142d14bb10f8dd1d (patch)
tree7f570d1a018a5ee94883d9ee04a345acf79c24e8
parentconsistency in calling usage, from Fritjof Bornebusch (diff)
downloadwireguard-openbsd-a19c2534b4be3829735c8863142d14bb10f8dd1d.tar.xz
wireguard-openbsd-a19c2534b4be3829735c8863142d14bb10f8dd1d.zip
Be more careful about meta->name. For weird input, it can be NULL.
Fixing a NULL access jsg@ found with afl.
-rw-r--r--usr.bin/mandoc/mdoc_term.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 0ad712c8637..5fa12c880ee 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.194 2014/11/27 22:27:40 schwarze Exp $ */
+/* $OpenBSD: mdoc_term.c,v 1.195 2014/11/28 16:02:23 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -993,6 +993,7 @@ termp_it_post(DECL_ARGS)
static int
termp_nm_pre(DECL_ARGS)
{
+ const char *cp;
if (MDOC_BLOCK == n->type) {
p->flags |= TERMP_PREKEEP;
@@ -1003,12 +1004,15 @@ termp_nm_pre(DECL_ARGS)
if (NULL == n->child)
return(0);
p->flags |= TERMP_NOSPACE;
- p->offset += term_len(p, 1) +
- (NULL == n->prev->child ?
- term_strlen(p, meta->name) :
- MDOC_TEXT == n->prev->child->type ?
- term_strlen(p, n->prev->child->string) :
- term_len(p, 5));
+ cp = NULL;
+ if (n->prev->child != NULL)
+ cp = n->prev->child->string;
+ if (cp == NULL)
+ cp = meta->name;
+ if (cp == NULL)
+ p->offset += term_len(p, 6);
+ else
+ p->offset += term_len(p, 1) + term_strlen(p, cp);
return(1);
}