summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2020-04-22 22:18:53 (GMT)
committerdgp <dgp@users.sourceforge.net>2020-04-22 22:18:53 (GMT)
commit3b1c00722a2401b6c4a6f80044364f6365da9749 (patch)
treec8b6c768062bec21c4acbe32f87830ee8b20214a
parent7f1a39781fafdf8fc0e10176a7fed4e0713a8866 (diff)
downloadtcl-3b1c00722a2401b6c4a6f80044364f6365da9749.zip
tcl-3b1c00722a2401b6c4a6f80044364f6365da9749.tar.gz
tcl-3b1c00722a2401b6c4a6f80044364f6365da9749.tar.bz2
Collection of tests checking read limit protections calling Tcl_UtfNext.
-rw-r--r--generic/tclTest.c8
-rw-r--r--tests/utf.test117
2 files changed, 121 insertions, 4 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 76a827a..d00c852 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -7138,7 +7138,7 @@ TestUtfNextCmd(
bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &numBytes);
- offset = numBytes + TCL_UTF_MAX; /* If no constraint is given, allow
+ offset = numBytes +TCL_UTF_MAX -1; /* If no constraint is given, allow
* the terminating NUL to limit
* operations. */
@@ -7149,12 +7149,12 @@ TestUtfNextCmd(
if (offset < 0) {
offset = 0;
}
- if (offset > numBytes + TCL_UTF_MAX) {
- offset = numBytes + TCL_UTF_MAX;
+ if (offset > numBytes +TCL_UTF_MAX -1) {
+ offset = numBytes +TCL_UTF_MAX -1;
}
}
- if (numBytes > sizeof(buffer)-2) {
+ if (numBytes > sizeof(buffer) - 2) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"\"testutfnext\" can only handle %d bytes",
sizeof(buffer) - 2));
diff --git a/tests/utf.test b/tests/utf.test
index beba98c..5058cbf 100644
--- a/tests/utf.test
+++ b/tests/utf.test
@@ -448,6 +448,123 @@ test utf-6.92 {Tcl_UtfNext, pointing to 2th byte of 4-byte invalid sequence} tes
test utf-6.93 {Tcl_UtfNext, pointing to 2th byte of 4-byte invalid sequence} testutfnext {
testutfnext \x80\x80\x80
} 1
+test utf-6.94 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext G 0
+} 0
+test utf-6.95 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0 0
+} 0
+test utf-6.96 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext AG 1
+} 1
+test utf-6.97 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext A\xA0 1
+} 1
+test utf-6.98 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xD0\xA0G 1
+} 0
+test utf-6.99 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xD0\xA0G 2
+} 2
+test utf-6.100 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xD0\xA0\xA0 1
+} 0
+test utf-6.101 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xD0\xA0\xA0 2
+} 2
+test utf-6.102 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xE8\xA0\xA0G 1
+} 0
+test utf-6.103 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xE8\xA0\xA0G 2
+} 0
+test utf-6.104 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xE8\xA0\xA0G 3
+} 3
+test utf-6.105 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xE8\xA0\xA0\xA0 1
+} 0
+test utf-6.106 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xE8\xA0\xA0\xA0 2
+} 0
+test utf-6.107 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xE8\xA0\xA0\xA0 3
+} 3
+test utf-6.108.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0G 1
+} 1
+test utf-6.108.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0G 1
+} 0
+test utf-6.109.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0G 2
+} 1
+test utf-6.109.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0G 2
+} 0
+test utf-6.110.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0G 3
+} 1
+test utf-6.110.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0G 3
+} 0
+test utf-6.111.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0G 4
+} 1
+test utf-6.111.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0G 4
+} 4
+test utf-6.112.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 1
+} 1
+test utf-6.112.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 1
+} 0
+test utf-6.113.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 2
+} 1
+test utf-6.113.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 2
+} 0
+test utf-6.114.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 3
+} 1
+test utf-6.114.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 3
+} 0
+test utf-6.115.0 {Tcl_UtfNext, read limits} {testutfnext ucs2} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 4
+} 1
+test utf-6.115.1 {Tcl_UtfNext, read limits} {testutfnext fullutf} {
+ testutfnext \xF2\xA0\xA0\xA0\xA0 4
+} 4
+test utf-6.116 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0G 0
+} 0
+test utf-6.117 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0G 1
+} 1
+test utf-6.118 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0 1
+} 1
+test utf-6.119 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0G 2
+} 1
+test utf-6.120 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0\xA0 2
+} 1
+test utf-6.121 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0\xA0G 3
+} 1
+test utf-6.122 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0\xA0\xA0 3
+} 1
+test utf-6.121 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0\xA0\xA0G 4
+} 1
+test utf-6.122 {Tcl_UtfNext, read limits} testutfnext {
+ testutfnext \xA0\xA0\xA0\xA0\xA0 4
+} 1
test utf-7.1 {Tcl_UtfPrev} testutfprev {
testutfprev {}