summaryrefslogtreecommitdiff
path: root/regress/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-12-19 04:57:12 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-12-19 04:57:12 +0000
commit471959573eec2067dcde4dd2b29ca931a17c6983 (patch)
treef3c1c78ee8e3c7ebca409b6762ba714c943f1f02 /regress/usr.bin/mandoc
parent40ac43966a02a9df27bd6166381399205a4db7a0 (diff)
Rewrite the low-level UTF-8 parser from scratch.
It accepted invalid byte sequences like 0xc080-c1bf, 0xe08080-e09fbf, 0xeda080-edbfbf, and 0xf0808080-f08fbfbf, produced valid roff Unicode escape sequences from them, and the algorithm contained strong defenses against any attempt to fix it. This cures an assertion failure in the terminal formatter caused by sneaking in ASCII 0x08 (backspace) by "encoding" it as an (invalid) multibyte UTF-8 sequence, found by jsg@ with afl. As a bonus, the new algorithm also reduces the code in the function by about 20%.
Diffstat (limited to 'regress/usr.bin/mandoc')
-rw-r--r--regress/usr.bin/mandoc/char/unicode/Makefile8
-rw-r--r--regress/usr.bin/mandoc/char/unicode/input.inbin0 -> 2371 bytes
-rw-r--r--regress/usr.bin/mandoc/char/unicode/input.out_ascii67
-rw-r--r--regress/usr.bin/mandoc/char/unicode/input.out_lint79
-rw-r--r--regress/usr.bin/mandoc/char/unicode/input.out_utf867
5 files changed, 217 insertions, 4 deletions
diff --git a/regress/usr.bin/mandoc/char/unicode/Makefile b/regress/usr.bin/mandoc/char/unicode/Makefile
index 5fd17875c22..b75ba6dbf07 100644
--- a/regress/usr.bin/mandoc/char/unicode/Makefile
+++ b/regress/usr.bin/mandoc/char/unicode/Makefile
@@ -1,13 +1,13 @@
-# $OpenBSD: Makefile,v 1.3 2014/10/29 03:39:26 schwarze Exp $
+# $OpenBSD: Makefile,v 1.4 2014/12/19 04:57:11 schwarze Exp $
-REGRESS_TARGETS = ascii invalid latin1 latin1diff
+REGRESS_TARGETS = ascii input invalid latin1 latin1diff
REGRESS_TARGETS += man mdoc named namediff nogroff
SKIP_ASCII = man mdoc
UTF8_TARGETS = ${REGRESS_TARGETS}
HTML_TARGETS = ascii invalid latin1 latin1diff named namediff nogroff
-LINT_TARGETS = invalid
+LINT_TARGETS = input invalid
-SKIP_GROFF = nogroff
+SKIP_GROFF = input nogroff
SKIP_GROFF_ASCII = latin1diff namediff
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/char/unicode/input.in b/regress/usr.bin/mandoc/char/unicode/input.in
new file mode 100644
index 00000000000..15a59f5bfd6
--- /dev/null
+++ b/regress/usr.bin/mandoc/char/unicode/input.in
Binary files differ
diff --git a/regress/usr.bin/mandoc/char/unicode/input.out_ascii b/regress/usr.bin/mandoc/char/unicode/input.out_ascii
new file mode 100644
index 00000000000..a9946d1b528
--- /dev/null
+++ b/regress/usr.bin/mandoc/char/unicode/input.out_ascii
@@ -0,0 +1,67 @@
+CHAR-UNICODE-INPUT(1) General Commands Manual CHAR-UNICODE-INPUT(1)
+
+
+
+NNAAMMEE
+ char-unicode-input - Unicode characters in the input file
+
+DDEESSCCRRIIPPTTIIOONN
+ lowest valid: <80>
+
+ OOnnee--bbyyttee rraannggee
+
+ U+0000 0x00 <NUL>? lowest ASCII
+ U+001f 0x1f <US>? highest ASCII control character
+ U+007f 0x7f <DEL>? highest ASCII
+ 0x80 ? leading lowest continuation
+ 0xbf ? leading highest continuation
+
+ TTwwoo--bbyyttee rraannggee
+
+ U+0000 0xc080 ?? lowest obfuscated ASCII
+ U+007f 0xc1bf ?? highest obfuscated ASCII
+ 0xc278 ?x ASCII continuation
+ U+0080 0xc280 <80><80> lowest two-byte
+ 0xc2c380 ?`A high continuation
+ U+07FF 0xdfbf <?><?> highest two-byte
+
+ TThhrreeee--bbyyttee rraannggee
+
+ U+0000 0xe08080 ??? lowest obfuscated ASCII
+ U+007f 0xe081bf ??? highest obfuscated ASCII
+ U+0080 0xe08280 ??? lowest obfuscated two-byte
+ U+07FF 0xe09fbf ??? highest obfuscated two-byte
+ U+0800 0xe0a080 <?><?> lowest three-byte
+ U+0FFF 0xe0bfbf <?><?> end of first middle byte
+ U+1000 0xe18080 <?><?> begin of second middle byte
+ U+CFFF 0xecbfbf <?><?> end of last normal middle byte
+ U+D000 0xed8080 <?><?> begin of strange middle byte
+ U+D7FF 0xed9fbf <?><?> highest public three-byte
+ U+D800 0xeda080 <?>??? lowest surrogate
+ U+DFFF 0xedbfbf <?>??? highest surrogate
+ U+E000 0xee8080 <?><?> lowest private use
+ U+FFFF 0xefbfbf <?><?> highest three-byte
+
+ FFoouurr--bbyyttee rraannggee
+
+ U+0000 0xf0808080 ???? lowest obfuscated ASCII
+ U+007f 0xf08081bf ???? highest obfuscated ASCII
+ U+0080 0xf0808280 ???? lowest obfuscated two-byte
+ U+07FF 0xf0809fbf ???? highest obfuscated two-byte
+ U+0800 0xf080a080 ???? lowest obfuscated three-byte
+ U+FFFF 0xf08fbfbf ???? highest obfuscated three-byte
+ U+10000 0xf0908080 <?><?> lowest four-byte
+ U+3FFFF 0xf0bfbfbf <?><?> end of first middle byte
+ U+40000 0xf1808080 <?><?> second middle byte
+ U+FFFFF 0xf3bfbfbf <?><?> last normal middle byte
+ U+100000 0xf4808080 <?><?> strange middle byte
+ U+10FFFF 0xf48fbfbf <?><?> last valid four-byte
+ U+110000 0xf4908080 ???? lowest beyond Unicode
+ U+13FFFF 0xf4bfbfbf ???? end of strange middle byte
+ U+140000 0xf5808080 ???? lowest invalid middle byte
+ U+1FFFFF 0xf7bfbfbf ???? highest four-byte
+ U+200000 0xf888808080 ????? lowest five-byte
+
+
+
+OpenBSD December 19, 2014 CHAR-UNICODE-INPUT(1)
diff --git a/regress/usr.bin/mandoc/char/unicode/input.out_lint b/regress/usr.bin/mandoc/char/unicode/input.out_lint
new file mode 100644
index 00000000000..77b6161cbab
--- /dev/null
+++ b/regress/usr.bin/mandoc/char/unicode/input.out_lint
@@ -0,0 +1,79 @@
+mandoc: input.in:10:21: ERROR: skipping bad character: 0x0
+mandoc: input.in:11:21: ERROR: skipping bad character: 0x1f
+mandoc: input.in:12:21: ERROR: skipping bad character: 0x7f
+mandoc: input.in:13:7: ERROR: skipping bad character: 0x80
+mandoc: input.in:14:7: ERROR: skipping bad character: 0xbf
+mandoc: input.in:20:15: ERROR: skipping bad character: 0xc0
+mandoc: input.in:20:16: ERROR: skipping bad character: 0x80
+mandoc: input.in:21:15: ERROR: skipping bad character: 0xc1
+mandoc: input.in:21:16: ERROR: skipping bad character: 0xbf
+mandoc: input.in:22:9: ERROR: skipping bad character: 0xc2
+mandoc: input.in:24:11: ERROR: skipping bad character: 0xc2
+mandoc: input.in:31:17: ERROR: skipping bad character: 0xc0
+mandoc: input.in:31:18: ERROR: skipping bad character: 0x80
+mandoc: input.in:31:19: ERROR: skipping bad character: 0x80
+mandoc: input.in:32:17: ERROR: skipping bad character: 0xe0
+mandoc: input.in:32:18: ERROR: skipping bad character: 0x81
+mandoc: input.in:32:19: ERROR: skipping bad character: 0xbf
+mandoc: input.in:33:17: ERROR: skipping bad character: 0xe0
+mandoc: input.in:33:18: ERROR: skipping bad character: 0x82
+mandoc: input.in:33:19: ERROR: skipping bad character: 0x80
+mandoc: input.in:34:17: ERROR: skipping bad character: 0xe0
+mandoc: input.in:34:18: ERROR: skipping bad character: 0x9f
+mandoc: input.in:34:19: ERROR: skipping bad character: 0xbf
+mandoc: input.in:41:25: ERROR: skipping bad character: 0xed
+mandoc: input.in:41:26: ERROR: skipping bad character: 0xa0
+mandoc: input.in:41:27: ERROR: skipping bad character: 0x80
+mandoc: input.in:42:25: ERROR: skipping bad character: 0xed
+mandoc: input.in:42:26: ERROR: skipping bad character: 0xbf
+mandoc: input.in:42:27: ERROR: skipping bad character: 0xbf
+mandoc: input.in:50:19: ERROR: skipping bad character: 0xf0
+mandoc: input.in:50:20: ERROR: skipping bad character: 0x80
+mandoc: input.in:50:21: ERROR: skipping bad character: 0x80
+mandoc: input.in:50:22: ERROR: skipping bad character: 0x80
+mandoc: input.in:51:19: ERROR: skipping bad character: 0xf0
+mandoc: input.in:51:20: ERROR: skipping bad character: 0x80
+mandoc: input.in:51:21: ERROR: skipping bad character: 0x81
+mandoc: input.in:51:22: ERROR: skipping bad character: 0xbf
+mandoc: input.in:52:19: ERROR: skipping bad character: 0xf0
+mandoc: input.in:52:20: ERROR: skipping bad character: 0x80
+mandoc: input.in:52:21: ERROR: skipping bad character: 0x82
+mandoc: input.in:52:22: ERROR: skipping bad character: 0x80
+mandoc: input.in:53:19: ERROR: skipping bad character: 0xf0
+mandoc: input.in:53:20: ERROR: skipping bad character: 0x80
+mandoc: input.in:53:21: ERROR: skipping bad character: 0x9f
+mandoc: input.in:53:22: ERROR: skipping bad character: 0xbf
+mandoc: input.in:54:19: ERROR: skipping bad character: 0xf0
+mandoc: input.in:54:20: ERROR: skipping bad character: 0x80
+mandoc: input.in:54:21: ERROR: skipping bad character: 0xa0
+mandoc: input.in:54:22: ERROR: skipping bad character: 0x80
+mandoc: input.in:55:19: ERROR: skipping bad character: 0xf0
+mandoc: input.in:55:20: ERROR: skipping bad character: 0x8f
+mandoc: input.in:55:21: ERROR: skipping bad character: 0xbf
+mandoc: input.in:55:22: ERROR: skipping bad character: 0xbf
+mandoc: input.in:62:31: ERROR: skipping bad character: 0xf4
+mandoc: input.in:62:32: ERROR: skipping bad character: 0x90
+mandoc: input.in:62:33: ERROR: skipping bad character: 0x80
+mandoc: input.in:62:34: ERROR: skipping bad character: 0x80
+mandoc: input.in:62:21: WARNING: invalid escape sequence: \[u110000]
+mandoc: input.in:63:31: ERROR: skipping bad character: 0xf4
+mandoc: input.in:63:32: ERROR: skipping bad character: 0xbf
+mandoc: input.in:63:33: ERROR: skipping bad character: 0xbf
+mandoc: input.in:63:34: ERROR: skipping bad character: 0xbf
+mandoc: input.in:63:21: WARNING: invalid escape sequence: \[u13FFFF]
+mandoc: input.in:64:31: ERROR: skipping bad character: 0xf5
+mandoc: input.in:64:32: ERROR: skipping bad character: 0x80
+mandoc: input.in:64:33: ERROR: skipping bad character: 0x80
+mandoc: input.in:64:34: ERROR: skipping bad character: 0x80
+mandoc: input.in:64:21: WARNING: invalid escape sequence: \[u140000]
+mandoc: input.in:65:31: ERROR: skipping bad character: 0xf7
+mandoc: input.in:65:32: ERROR: skipping bad character: 0xbf
+mandoc: input.in:65:33: ERROR: skipping bad character: 0xbf
+mandoc: input.in:65:34: ERROR: skipping bad character: 0xbf
+mandoc: input.in:65:21: WARNING: invalid escape sequence: \[u1FFFFF]
+mandoc: input.in:66:33: ERROR: skipping bad character: 0xf8
+mandoc: input.in:66:34: ERROR: skipping bad character: 0x88
+mandoc: input.in:66:35: ERROR: skipping bad character: 0x80
+mandoc: input.in:66:36: ERROR: skipping bad character: 0x80
+mandoc: input.in:66:37: ERROR: skipping bad character: 0x80
+mandoc: input.in:66:23: WARNING: invalid escape sequence: \[u200000]
diff --git a/regress/usr.bin/mandoc/char/unicode/input.out_utf8 b/regress/usr.bin/mandoc/char/unicode/input.out_utf8
new file mode 100644
index 00000000000..fc7a59e1092
--- /dev/null
+++ b/regress/usr.bin/mandoc/char/unicode/input.out_utf8
@@ -0,0 +1,67 @@
+CHAR-UNICODE-INPUT(1) General Commands Manual CHAR-UNICODE-INPUT(1)
+
+
+
+NNAAMMEE
+ char-unicode-input - Unicode characters in the input file
+
+DDEESSCCRRIIPPTTIIOONN
+ lowest valid: �
+
+ OOnnee--bbyyttee rraannggee
+
+ U+0000 0x00 �? lowest ASCII
+ U+001f 0x1f �? highest ASCII control character
+ U+007f 0x7f �? highest ASCII
+ 0x80 ? leading lowest continuation
+ 0xbf ? leading highest continuation
+
+ TTwwoo--bbyyttee rraannggee
+
+ U+0000 0xc080 ?? lowest obfuscated ASCII
+ U+007f 0xc1bf ?? highest obfuscated ASCII
+ 0xc278 ?x ASCII continuation
+ U+0080 0xc280 �� lowest two-byte
+ 0xc2c380 ?À high continuation
+ U+07FF 0xdfbf ߿߿ highest two-byte
+
+ TThhrreeee--bbyyttee rraannggee
+
+ U+0000 0xe08080 ??? lowest obfuscated ASCII
+ U+007f 0xe081bf ??? highest obfuscated ASCII
+ U+0080 0xe08280 ??? lowest obfuscated two-byte
+ U+07FF 0xe09fbf ??? highest obfuscated two-byte
+ U+0800 0xe0a080 ࠀࠀ lowest three-byte
+ U+0FFF 0xe0bfbf ࿿࿿ end of first middle byte
+ U+1000 0xe18080 ကက begin of second middle byte
+ U+CFFF 0xecbfbf 쿿쿿 end of last normal middle byte
+ U+D000 0xed8080 퀀퀀 begin of strange middle byte
+ U+D7FF 0xed9fbf ퟿퟿ highest public three-byte
+ U+D800 0xeda080 ??? lowest surrogate
+ U+DFFF 0xedbfbf ??? highest surrogate
+ U+E000 0xee8080  lowest private use
+ U+FFFF 0xefbfbf ￿￿ highest three-byte
+
+ FFoouurr--bbyyttee rraannggee
+
+ U+0000 0xf0808080 ???? lowest obfuscated ASCII
+ U+007f 0xf08081bf ???? highest obfuscated ASCII
+ U+0080 0xf0808280 ???? lowest obfuscated two-byte
+ U+07FF 0xf0809fbf ???? highest obfuscated two-byte
+ U+0800 0xf080a080 ???? lowest obfuscated three-byte
+ U+FFFF 0xf08fbfbf ???? highest obfuscated three-byte
+ U+10000 0xf0908080 𐀀𐀀 lowest four-byte
+ U+3FFFF 0xf0bfbfbf 𿿿𿿿 end of first middle byte
+ U+40000 0xf1808080 񀀀񀀀 second middle byte
+ U+FFFFF 0xf3bfbfbf 󿿿󿿿 last normal middle byte
+ U+100000 0xf4808080 􀀀􀀀 strange middle byte
+ U+10FFFF 0xf48fbfbf 􏿿􏿿 last valid four-byte
+ U+110000 0xf4908080 ???? lowest beyond Unicode
+ U+13FFFF 0xf4bfbfbf ???? end of strange middle byte
+ U+140000 0xf5808080 ???? lowest invalid middle byte
+ U+1FFFFF 0xf7bfbfbf ???? highest four-byte
+ U+200000 0xf888808080 ????? lowest five-byte
+
+
+
+OpenBSD December 19, 2014 CHAR-UNICODE-INPUT(1)