The code already pays attention not to close the same block twice.
authorschwarze <schwarze@openbsd.org>
Mon, 22 Dec 2014 23:26:20 +0000 (23:26 +0000)
committerschwarze <schwarze@openbsd.org>
Mon, 22 Dec 2014 23:26:20 +0000 (23:26 +0000)
Similarly, avoid having the same block break two other blocks.
In some situations, this could lead to an endless loop in rew_sub()
found by jsg@ with afl.
Minimal example:  .Po Ao Pc Bo Pc Ac Bc

regress/usr.bin/mandoc/mdoc/Makefile
regress/usr.bin/mandoc/mdoc/break/Makefile [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/break/twice.in [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/break/twice.out_ascii [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/break/twice.out_lint [new file with mode: 0644]
usr.bin/mandoc/mdoc_macro.c

index 6006c7d..532158b 100644 (file)
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.30 2014/11/27 16:20:27 schwarze Exp $
+# $OpenBSD: Makefile,v 1.31 2014/12/22 23:26:20 schwarze Exp $
 
 SUBDIR  = Ad An Ap Aq Ar At Bd Bf Bk Bl Brq Bx Cd Cm
 SUBDIR += D1 Db Dd Dl Dq Dt Dv Em Eo Er Ev Ex Fd Fl Fo Ft Ic In Lb Li Lk
 SUBDIR += Ms Mt Nd Nm No Ns Oo Op Os Ox Pa Pf Pp Qq Rs Rv
-SUBDIR += Sh Sm Sq St Sx Sy Tn Ux Va Vt Xr blank
+SUBDIR += Sh Sm Sq St Sx Sy Tn Ux Va Vt Xr blank break
 
 .include "../Makefile.sub"
 .include <bsd.subdir.mk>
diff --git a/regress/usr.bin/mandoc/mdoc/break/Makefile b/regress/usr.bin/mandoc/mdoc/break/Makefile
new file mode 100644 (file)
index 0000000..1fd82f7
--- /dev/null
@@ -0,0 +1,11 @@
+# $OpenBSD: Makefile,v 1.1 2014/12/22 23:26:20 schwarze Exp $
+
+REGRESS_TARGETS        = twice
+LINT_TARGETS   = twice
+
+# groff-1.22.3 defect:
+# - non-matching enclosure end macro prints a closing delimiter
+
+SKIP_GROFF     = twice
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/mdoc/break/twice.in b/regress/usr.bin/mandoc/mdoc/break/twice.in
new file mode 100644 (file)
index 0000000..cb6642a
--- /dev/null
@@ -0,0 +1,14 @@
+.Dd December 23, 2014
+.Dt BREAK-TWICE 1
+.Os OpenBSD
+.Sh NAME
+.Nm break-twice
+.Nd the same block breaking two other blocks
+.Sh DESCRIPTION
+.Po po
+.Ao ao pc
+.Pc
+.Bo bo pc
+.Pc ac
+.Ac bc
+.Bc
diff --git a/regress/usr.bin/mandoc/mdoc/break/twice.out_ascii b/regress/usr.bin/mandoc/mdoc/break/twice.out_ascii
new file mode 100644 (file)
index 0000000..6d91ffa
--- /dev/null
@@ -0,0 +1,9 @@
+BREAK-TWICE(1)              General Commands Manual             BREAK-TWICE(1)
+
+N\bNA\bAM\bME\bE
+     b\bbr\bre\bea\bak\bk-\b-t\btw\bwi\bic\bce\be - the same block breaking two other blocks
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     (po <ao pc) [bo pc ac> bc]
+
+OpenBSD                        December 23, 2014                       OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/break/twice.out_lint b/regress/usr.bin/mandoc/mdoc/break/twice.out_lint
new file mode 100644 (file)
index 0000000..bedf7b2
--- /dev/null
@@ -0,0 +1,2 @@
+mandoc: twice.in:10:2: WARNING: blocks badly nested: Pc breaks Ao
+mandoc: twice.in:13:2: WARNING: blocks badly nested: Ac breaks Bo
index 14c686f..ec6507f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mdoc_macro.c,v 1.116 2014/12/20 02:26:42 schwarze Exp $ */
+/*     $OpenBSD: mdoc_macro.c,v 1.117 2014/12/22 23:26:20 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -361,7 +361,7 @@ rew_dohalt(enum mdoct tok, enum mdoc_type type,
         * When starting to rewind, skip plain text
         * and nodes that have already been rewound.
         */
-       if (MDOC_TEXT == p->type || MDOC_VALID & p->flags)
+       if (p->type == MDOC_TEXT || p->flags & (MDOC_VALID | MDOC_BREAK))
                return(REWIND_MORE);
 
        /*
@@ -744,7 +744,7 @@ blk_exp_close(MACRO_PROT_ARGS)
        atok = rew_alt(tok);
        body = endbody = later = NULL;
        for (n = mdoc->last; n; n = n->parent) {
-               if (n->flags & MDOC_VALID)
+               if (n->flags & (MDOC_VALID | MDOC_BREAK))
                        continue;
 
                /* Remember the start of our own body. */