From de25e57757f7ad49514c641e9a5af4f925f5ebfe Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 12 Sep 2017 18:21:03 +0000 Subject: Do not segfault when there are two .Dt macros, the first without an architecture argument and the second with an invalid one. Bug found by jsg@ with afl(1). --- mdoc_validate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mdoc_validate.c') diff --git a/mdoc_validate.c b/mdoc_validate.c index 3a9b86f3..e95bebfa 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.352 2017/08/02 13:29:04 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.353 2017/09/12 18:21:03 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -1914,7 +1914,10 @@ post_root(POST_ARGS) arch++; if (*arch == NULL) { n = mdoc->first->child; - while (n->tok != MDOC_Dt) + while (n->tok != MDOC_Dt || + n->child == NULL || + n->child->next == NULL || + n->child->next->next == NULL) n = n->next; n = n->child->next->next; mandoc_vmsg(MANDOCERR_ARCH_BAD, -- cgit v1.2.3-56-ge451