]> git.cameronkatri.com Git - mandoc.git/commitdiff
Do not segfault when there are two .Dt macros, the first without
authorIngo Schwarze <schwarze@openbsd.org>
Tue, 12 Sep 2017 18:21:03 +0000 (18:21 +0000)
committerIngo Schwarze <schwarze@openbsd.org>
Tue, 12 Sep 2017 18:21:03 +0000 (18:21 +0000)
an architecture argument and the second with an invalid one.
Bug found by jsg@ with afl(1).

mdoc_validate.c

index 3a9b86f3fd2b555741c4576130e1c73300f92578..e95bebfa1067cd4000d8d24c2930585521ce62bf 100644 (file)
@@ -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 <kristaps@bsd.lv>
  * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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,