summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2019-11-09 14:39:43 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2019-11-09 14:39:43 +0000
commita3dda3f5c7bb7231ba8d6e7984e9822ee635b295 (patch)
treee53d19ebc6894ccf503fd3a2d32593f3212b0505
parenta9c6f194bd133c7e1278206aae805e4e633eac3f (diff)
In the past, generating comment nodes stopped at the .TH or .Dd
macro, which is usually close to the beginning of the file, right after the Copyright header comments. But espie@ found horrible input files in the textproc/fstrcmp port that generate lots of parse nodes before even getting to the header macro. In some formatters, comment nodes after some kinds of real content triggered assertions. So make sure generation of comment nodes stops once real content is encountered.
-rw-r--r--usr.bin/mandoc/mandoc_parse.h3
-rw-r--r--usr.bin/mandoc/roff.c12
2 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/mandoc/mandoc_parse.h b/usr.bin/mandoc/mandoc_parse.h
index 650b716c1ae..1821c1efd54 100644
--- a/usr.bin/mandoc/mandoc_parse.h
+++ b/usr.bin/mandoc/mandoc_parse.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandoc_parse.h,v 1.3 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: mandoc_parse.h,v 1.4 2019/11/09 14:39:42 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -29,6 +29,7 @@
#define MPARSE_UTF8 (1 << 4) /* accept UTF-8 input */
#define MPARSE_LATIN1 (1 << 5) /* accept ISO-LATIN-1 input */
#define MPARSE_VALIDATE (1 << 6) /* call validation functions */
+#define MPARSE_COMMENT (1 << 7) /* save comments in the tree */
struct roff_meta;
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 0b1c5fb652b..a4fe4f06df2 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.238 2019/07/01 22:43:03 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.239 2019/11/09 14:39:42 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -769,6 +769,7 @@ void
roff_reset(struct roff *r)
{
roff_free1(r);
+ r->options |= MPARSE_COMMENT;
r->format = r->options & (MPARSE_MDOC | MPARSE_MAN);
r->control = '\0';
r->escape = '\\';
@@ -798,7 +799,7 @@ roff_alloc(int options)
r = mandoc_calloc(1, sizeof(struct roff));
r->reqtab = roffhash_alloc(0, ROFF_RENAMED);
- r->options = options;
+ r->options = options | MPARSE_COMMENT;
r->format = options & (MPARSE_MDOC | MPARSE_MAN);
r->mstackpos = -1;
r->rstackpos = -1;
@@ -1244,7 +1245,7 @@ roff_expand(struct roff *r, struct buf *buf, int ln, int pos, char newesc)
* in the syntax tree.
*/
- if (newesc != ASCII_ESC && r->format == 0) {
+ if (newesc != ASCII_ESC && r->options & MPARSE_COMMENT) {
while (*ep == ' ' || *ep == '\t')
ep--;
ep[1] = '\0';
@@ -1813,8 +1814,10 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
roff_addtbl(r->man, ln, r->tbl);
return e;
}
- if ( ! ctl)
+ if ( ! ctl) {
+ r->options &= ~MPARSE_COMMENT;
return roff_parsetext(r, buf, pos, offs) | e;
+ }
/* Skip empty request lines. */
@@ -1837,6 +1840,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
/* No scope is open. This is a new request or macro. */
+ r->options &= ~MPARSE_COMMENT;
spos = pos;
t = roff_parse(r, buf->buf, &pos, ln, ppos);