summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-09-13 07:48:13 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-09-13 07:48:13 (GMT)
commitd9b2b3f0125cf86bd1e39eae4fdfd3b9a58cf75b (patch)
tree8f9af2b6306d56bacc8709a04518a9e0da661cff
parent7ddf89897fec5a06a8df45f510984b16e93aa117 (diff)
parentaccc6b2ae999a22f2993b26e6a980a0f9a8fe0c2 (diff)
downloadtcl-d9b2b3f0125cf86bd1e39eae4fdfd3b9a58cf75b.zip
tcl-d9b2b3f0125cf86bd1e39eae4fdfd3b9a58cf75b.tar.gz
tcl-d9b2b3f0125cf86bd1e39eae4fdfd3b9a58cf75b.tar.bz2
Fix [1073daf086]: Bug in handling illegal utf-8 sequence
-rw-r--r--generic/tclIO.c19
-rw-r--r--tests/io.test4
2 files changed, 10 insertions, 13 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 6b7ccdf..d228d50 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -4278,6 +4278,7 @@ Write(
char *nextNewLine = NULL;
int endEncoding, saved = 0, total = 0, flushed = 0, needNlFlush = 0;
char safe[BUFFER_PADDING];
+ int encodingError = 0;
if (srcLen) {
WillWrite(chanPtr);
@@ -4294,7 +4295,7 @@ Write(
nextNewLine = (char *)memchr(src, '\n', srcLen);
}
- while (srcLen + saved + endEncoding > 0) {
+ while (srcLen + saved + endEncoding > 0 && !encodingError) {
ChannelBuffer *bufPtr;
char *dst;
int result, srcRead, dstLen, dstWrote, srcLimit = srcLen;
@@ -4335,16 +4336,8 @@ Write(
statePtr->outputEncodingFlags &= ~TCL_ENCODING_START;
if ((result != TCL_OK) && (srcRead + dstWrote == 0)) {
- /*
- * We're reading from invalid/incomplete UTF-8.
- */
-
- ReleaseChannelBuffer(bufPtr);
- if (total == 0) {
- Tcl_SetErrno(EINVAL);
- return -1;
- }
- break;
+ encodingError = 1;
+ result = TCL_OK;
}
bufPtr->nextAdded += dstWrote;
@@ -4442,6 +4435,10 @@ Write(
}
}
+ if (encodingError) {
+ Tcl_SetErrno(EINVAL);
+ return -1;
+ }
return total;
}
diff --git a/tests/io.test b/tests/io.test
index edadfed..94d8764 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -8434,7 +8434,7 @@ test io-60.1 {writing illegal utf sequences} {fileevent testbytestring} {
set out [open $path(script) w]
puts $out "catch {load $::tcltestlib Tcltest}"
puts $out {
- puts [testbytestring \xE2]
+ puts ABC[testbytestring \xE2]
exit 1
}
proc readit {pipe} {
@@ -8458,7 +8458,7 @@ test io-60.1 {writing illegal utf sequences} {fileevent testbytestring} {
# cut of the remainder of the error stack, especially the filename
set result [lreplace $result 3 3 [lindex [split [lindex $result 3] \n] 0]]
list $x $result
-} {1 {gets {} catch {error writing "stdout": invalid argument}}}
+} {1 {gets ABC catch {error writing "stdout": invalid argument}}}
test io-61.1 {Reset eof state after changing the eof char} -setup {
set datafile [makeFile {} eofchar]