summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2011-01-09 13:16:48 +0000
committerschwarze <schwarze@openbsd.org>2011-01-09 13:16:48 +0000
commit609398efd4476313c8df3e646acd40ef139f3a0b (patch)
tree3828f622a31eeef0d56db073442decfeaa70b8ab
parentadd yet another check: obviously in a @depend line, if the def part doesn't (diff)
downloadwireguard-openbsd-609398efd4476313c8df3e646acd40ef139f3a0b.tar.xz
wireguard-openbsd-609398efd4476313c8df3e646acd40ef139f3a0b.zip
Make sure coding errors cannot make us miss fatal parsing errors
by assert(3)ing valid parser state in the main parsing functions; from kristaps@.
-rw-r--r--usr.bin/mandoc/main.c10
-rw-r--r--usr.bin/mandoc/man.333
-rw-r--r--usr.bin/mandoc/man.c20
-rw-r--r--usr.bin/mandoc/mdoc.333
-rw-r--r--usr.bin/mandoc/mdoc.c19
5 files changed, 56 insertions, 59 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 9715f047c89..6e699387762 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.64 2011/01/04 22:28:17 schwarze Exp $ */
+/* $Id: main.c,v 1.65 2011/01/09 13:16:48 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -794,6 +794,14 @@ rerun:
}
/*
+ * If we encounter errors in the recursive parsebuf()
+ * call, make sure we don't continue parsing.
+ */
+
+ if (MANDOCLEVEL_FATAL <= file_status)
+ break;
+
+ /*
* If input parsers have not been allocated, do so now.
* We keep these instanced betwen parsers, but set them
* locally per parse routine since we can use different
diff --git a/usr.bin/mandoc/man.3 b/usr.bin/mandoc/man.3
index a1a9ea08640..8d8eaec9327 100644
--- a/usr.bin/mandoc/man.3
+++ b/usr.bin/mandoc/man.3
@@ -1,4 +1,4 @@
-.\" $Id: man.3,v 1.20 2011/01/04 22:28:17 schwarze Exp $
+.\" $Id: man.3,v 1.21 2011/01/09 13:16:48 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 4 2011 $
+.Dd $Mdocdate: January 9 2011 $
.Dt MAN 3
.Os
.Sh NAME
@@ -105,6 +105,16 @@ See
for details.
.El
.Ss Functions
+If
+.Fn man_addspan ,
+.Fn man_parseln ,
+or
+.Fn man_endparse
+return 0, calls to any function but
+.Fn man_reset
+or
+.Fn man_free
+will raise an assertion.
.Bl -ohang
.It Fn man_addspan
Add a table span to the parsing stream.
@@ -115,8 +125,8 @@ The
.Fa data
pointer is passed to
.Fa msgs .
-Returns NULL on failure.
-If non-NULL, the pointer must be freed with
+Always returns a valid pointer.
+The pointer must be freed with
.Fn man_free .
.It Fn man_reset
Reset the parser for another parse routine.
@@ -135,26 +145,11 @@ The input buffer
is modified by this function.
.It Fn man_endparse
Signals that the parse is complete.
-Note that if
-.Fn man_endparse
-is called subsequent to
-.Fn man_node ,
-the resulting tree is incomplete.
Returns 0 on failure, 1 on success.
.It Fn man_node
Returns the first node of the parse.
-Note that if
-.Fn man_parseln
-or
-.Fn man_endparse
-return 0, the tree will be incomplete.
.It Fn man_meta
Returns the document's parsed meta-data.
-If this information has not yet been supplied or
-.Fn man_parseln
-or
-.Fn man_endparse
-return 0, the data will be incomplete.
.El
.Ss Variables
The following variables are also defined:
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 2f534e1d9d1..09d79242b7c 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.52 2011/01/04 22:28:17 schwarze Exp $ */
+/* $Id: man.c,v 1.53 2011/01/09 13:16:48 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -60,7 +60,8 @@ const struct man_node *
man_node(const struct man *m)
{
- return(MAN_HALT & m->flags ? NULL : m->first);
+ assert( ! (MAN_HALT & m->flags));
+ return(m->first);
}
@@ -68,7 +69,8 @@ const struct man_meta *
man_meta(const struct man *m)
{
- return(MAN_HALT & m->flags ? NULL : &m->meta);
+ assert( ! (MAN_HALT & m->flags));
+ return(&m->meta);
}
@@ -111,9 +113,8 @@ int
man_endparse(struct man *m)
{
- if (MAN_HALT & m->flags)
- return(0);
- else if (man_macroend(m))
+ assert( ! (MAN_HALT & m->flags));
+ if (man_macroend(m))
return(1);
m->flags |= MAN_HALT;
return(0);
@@ -124,9 +125,7 @@ int
man_parseln(struct man *m, int ln, char *buf, int offs)
{
- if (MAN_HALT & m->flags)
- return(0);
-
+ assert( ! (MAN_HALT & m->flags));
return(('.' == buf[offs] || '\'' == buf[offs]) ?
man_pmacro(m, ln, buf, offs) :
man_ptext(m, ln, buf, offs));
@@ -359,6 +358,7 @@ int
man_addspan(struct man *m, const struct tbl_span *sp)
{
+ assert( ! (MAN_HALT & m->flags));
if ( ! man_span_alloc(m, sp))
return(0);
return(man_descope(m, 0, 0));
@@ -461,7 +461,7 @@ man_ptext(struct man *m, int line, char *buf, int offs)
}
-int
+static int
man_pmacro(struct man *m, int ln, char *buf, int offs)
{
int i, j, ppos;
diff --git a/usr.bin/mandoc/mdoc.3 b/usr.bin/mandoc/mdoc.3
index 556b5792546..bb576d4bad4 100644
--- a/usr.bin/mandoc/mdoc.3
+++ b/usr.bin/mandoc/mdoc.3
@@ -1,4 +1,4 @@
-.\" $Id: mdoc.3,v 1.15 2011/01/04 22:28:17 schwarze Exp $
+.\" $Id: mdoc.3,v 1.16 2011/01/09 13:16:48 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 4 2011 $
+.Dd $Mdocdate: January 9 2011 $
.Dt MDOC 3
.Os
.Sh NAME
@@ -96,6 +96,16 @@ See
for details.
.El
.Ss Functions
+If
+.Fn mdoc_addspan ,
+.Fn mdoc_parseln ,
+or
+.Fn mdoc_endparse
+return 0, calls to any function but
+.Fn mdoc_reset
+or
+.Fn mdoc_free
+will raise an assertion.
.Bl -ohang
.It Fn mdoc_addspan
Add a table span to the parsing stream.
@@ -106,8 +116,8 @@ The
.Fa data
pointer is passed to
.Fa msgs .
-Returns NULL on failure.
-If non-NULL, the pointer must be freed with
+Always returns a valid pointer.
+The pointer must be freed with
.Fn mdoc_free .
.It Fn mdoc_reset
Reset the parser for another parse routine.
@@ -127,26 +137,11 @@ The input buffer
is modified by this function.
.It Fn mdoc_endparse
Signals that the parse is complete.
-Note that if
-.Fn mdoc_endparse
-is called subsequent to
-.Fn mdoc_node ,
-the resulting tree is incomplete.
Returns 0 on failure, 1 on success.
.It Fn mdoc_node
Returns the first node of the parse.
-Note that if
-.Fn mdoc_parseln
-or
-.Fn mdoc_endparse
-return 0, the tree will be incomplete.
.It Fn mdoc_meta
Returns the document's parsed meta-data.
-If this information has not yet been supplied or
-.Fn mdoc_parseln
-or
-.Fn mdoc_endparse
-return 0, the data will be incomplete.
.El
.Ss Variables
.Bl -ohang
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index 51386a989ab..a6b50af9e83 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.77 2011/01/04 22:28:17 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.78 2011/01/09 13:16:48 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -102,7 +102,8 @@ const struct mdoc_node *
mdoc_node(const struct mdoc *m)
{
- return(MDOC_HALT & m->flags ? NULL : m->first);
+ assert( ! (MDOC_HALT & m->flags));
+ return(m->first);
}
@@ -110,7 +111,8 @@ const struct mdoc_meta *
mdoc_meta(const struct mdoc *m)
{
- return(MDOC_HALT & m->flags ? NULL : &m->meta);
+ assert( ! (MDOC_HALT & m->flags));
+ return(&m->meta);
}
@@ -211,9 +213,8 @@ int
mdoc_endparse(struct mdoc *m)
{
- if (MDOC_HALT & m->flags)
- return(0);
- else if (mdoc_macroend(m))
+ assert( ! (MDOC_HALT & m->flags));
+ if (mdoc_macroend(m))
return(1);
m->flags |= MDOC_HALT;
return(0);
@@ -223,8 +224,7 @@ int
mdoc_addspan(struct mdoc *m, const struct tbl_span *sp)
{
- if (MDOC_HALT & m->flags)
- return(0);
+ assert( ! (MDOC_HALT & m->flags));
/* No text before an initial macro. */
@@ -246,8 +246,7 @@ int
mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs)
{
- if (MDOC_HALT & m->flags)
- return(0);
+ assert( ! (MDOC_HALT & m->flags));
m->flags |= MDOC_NEWLINE;