summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2013-05-30 03:52:00 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2013-05-30 03:52:00 +0000
commit0320d60443aaba16d54fb38a5e60729174532605 (patch)
tree06274afd7ca13fdb80e9871c1d7b2335e657a2db /usr.bin/mandoc
parent58df122e5a509bb409cf37864c85cab1ef3237c3 (diff)
Reject non-printable characters found in the input stream even when
preceded by a backslash; otherwise, the escape sequence would later be identified as invalid and the non-printable character would be passed through to the output backends, sometimes triggering assertions. Reported by Mike Small <smallm at panix dot com> on the mdocml discuss list.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/read.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 59692abf743..245ad5d9587 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,7 +1,7 @@
-/* $Id: read.c,v 1.12 2012/11/19 22:28:35 schwarze Exp $ */
+/* $Id: read.c,v 1.13 2013/05/30 03:51:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011, 2012, 2013 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
@@ -317,6 +317,15 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int start)
break;
}
+ /*
+ * Make sure we have space for at least
+ * one backslash and one other character
+ * and the trailing NUL byte.
+ */
+
+ if (pos + 2 >= (int)ln.sz)
+ resize_buf(&ln, 256);
+
/*
* Warn about bogus characters. If you're using
* non-ASCII encoding, you're screwing your
@@ -333,8 +342,6 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int start)
mandoc_msg(MANDOCERR_BADCHAR, curp,
curp->line, pos, NULL);
i++;
- if (pos >= (int)ln.sz)
- resize_buf(&ln, 256);
ln.buf[pos++] = '?';
continue;
}
@@ -342,8 +349,6 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int start)
/* Trailing backslash = a plain char. */
if ('\\' != blk.buf[i] || i + 1 == (int)blk.sz) {
- if (pos >= (int)ln.sz)
- resize_buf(&ln, 256);
ln.buf[pos++] = blk.buf[i++];
continue;
}
@@ -385,10 +390,20 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int start)
break;
}
- /* Some other escape sequence, copy & cont. */
+ /* Catch escaped bogus characters. */
- if (pos + 1 >= (int)ln.sz)
- resize_buf(&ln, 256);
+ c = (unsigned char) blk.buf[i+1];
+
+ if ( ! (isascii(c) &&
+ (isgraph(c) || isblank(c)))) {
+ mandoc_msg(MANDOCERR_BADCHAR, curp,
+ curp->line, pos, NULL);
+ i += 2;
+ ln.buf[pos++] = '?';
+ continue;
+ }
+
+ /* Some other escape sequence, copy & cont. */
ln.buf[pos++] = blk.buf[i++];
ln.buf[pos++] = blk.buf[i++];