summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2012-11-19 22:28:36 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2012-11-19 22:28:36 +0000
commitf6aefaa94996adb3a94cf829d7d536f2457f186f (patch)
tree7e9d0f5a59bcbb947052eb699b49cf422ce4233b
parent714b5995a4bacf5d3b4f69e18b24f338eb290330 (diff)
Do not crash on stray .Ta macros found outside column lists.
Problem reported by jmc@, thanks.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/Makefile6
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/bareTa.in21
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/bareTa.out_ascii15
-rw-r--r--usr.bin/mandoc/mandoc.h4
-rw-r--r--usr.bin/mandoc/mdoc_macro.c16
-rw-r--r--usr.bin/mandoc/read.c5
6 files changed, 56 insertions, 11 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/Makefile b/regress/usr.bin/mandoc/mdoc/Bl/Makefile
index 089f8547b27..6e3472a8d2d 100644
--- a/regress/usr.bin/mandoc/mdoc/Bl/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Bl/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.14 2012/11/18 17:59:03 schwarze Exp $
+# $OpenBSD: Makefile,v 1.15 2012/11/19 22:28:35 schwarze Exp $
REGRESS_TARGETS = item inset diag ohang bullet dash enum hang tag
REGRESS_TARGETS += column extend nested
-REGRESS_TARGETS += multitype multitag empty unclosed break broken
+REGRESS_TARGETS += multitype multitag empty bareTa unclosed break broken
# groff-1.20.1 defects:
# - empty lists ruin indentation and sometimes cause empty lines
@@ -12,6 +12,6 @@ REGRESS_TARGETS += multitype multitag empty unclosed break broken
SKIP_GROFF ?= empty break broken
-SKIP_TMAN ?= column multitype multitag break broken
+SKIP_TMAN ?= column multitype multitag bareTa break broken
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/bareTa.in b/regress/usr.bin/mandoc/mdoc/Bl/bareTa.in
new file mode 100644
index 00000000000..20f003766a9
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/bareTa.in
@@ -0,0 +1,21 @@
+.Dd November 12, 2012
+.Dt TA-BARE 1
+.Os OpenBSD
+.Sh NAME
+.Nm Ta-bare
+.Nd bare tabular column macro
+.Sh DESCRIPTION
+initial text
+.Ta ignored arguments
+middle text
+.Bl -item -offset indent
+.It
+.Ta ignored arguments
+indented text
+.El
+middle text
+.Bl -dash
+.It Ta ignored arguments
+indented text
+.El
+final text
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/bareTa.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/bareTa.out_ascii
new file mode 100644
index 00000000000..c5139d9cee5
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/bareTa.out_ascii
@@ -0,0 +1,15 @@
+TA-BARE(1) OpenBSD Reference Manual TA-BARE(1)
+
+NNAAMMEE
+ TTaa--bbaarree - bare tabular column macro
+
+DDEESSCCRRIIPPTTIIOONN
+ initial text middle text
+
+ indented text
+ middle text
+
+ -- indented text
+ final text
+
+OpenBSD November 12, 2012 OpenBSD
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 14f32bf00cc..e10d6390d82 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,6 +1,7 @@
-/* $Id: mandoc.h,v 1.49 2012/11/16 22:20:40 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.50 2012/11/19 22:28:35 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2012 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -135,6 +136,7 @@ enum mandocerr {
MANDOCERR_MACRO, /* skipping unknown macro */
MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */
MANDOCERR_ARGCOUNT, /* argument count wrong */
+ MANDOCERR_STRAYTA, /* skipping column outside column list */
MANDOCERR_NOSCOPE, /* skipping end of block that is not open */
MANDOCERR_SCOPEBROKEN, /* missing end of block */
MANDOCERR_SCOPEEXIT, /* scope open on exit */
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index 8093a52a50a..b869c6fa3fe 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.77 2012/11/18 00:05:28 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.78 2012/11/19 22:28:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -1755,16 +1755,22 @@ phrase(struct mdoc *mdoc, int line, int ppos, char *buf)
static int
phrase_ta(MACRO_PROT_ARGS)
{
+ struct mdoc_node *n;
int la;
enum mdoct ntok;
enum margserr ac;
char *p;
- /*
- * FIXME: this is overly restrictive: if the `Ta' is unexpected,
- * it should simply error out with ARGSLOST.
- */
+ /* Make sure we are in a column list or ignore this macro. */
+ n = mdoc->last;
+ while (NULL != n && MDOC_Bl != n->tok)
+ n = n->parent;
+ if (NULL == n || LIST_column != n->norm->Bl.type) {
+ mdoc_pmsg(mdoc, line, ppos, MANDOCERR_STRAYTA);
+ return(1);
+ }
+ /* Advance to the next column. */
if ( ! rew_sub(MDOC_BODY, mdoc, MDOC_It, line, ppos))
return(0);
if ( ! mdoc_body_alloc(mdoc, line, ppos, MDOC_It))
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 2150a5550bd..59692abf743 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,7 +1,7 @@
-/* $Id: read.c,v 1.11 2012/11/16 22:20:40 schwarze Exp $ */
+/* $Id: read.c,v 1.12 2012/11/19 22:28:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -169,6 +169,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"skipping unknown macro",
"NOT IMPLEMENTED, please use groff: skipping request",
"argument count wrong",
+ "skipping column outside column list",
"skipping end of block that is not open",
"missing end of block",
"scope open on exit",