Package: expect
Version: 5.45-6
Severity: normal
Tags: patch

Sometimes fake EOFs occur when running with a multi-byte locales over
serial ports. The reason is when Tcl_ReadChars() returns 0 it is
considered EOF in expRead().

When select() detects there is at least one byte available, it does not
mean a multibyte-locale character is also available because it may be
incomplete, so Tcl_ReadChars() may return 0 and it is not an EOF
condition, therefore explicit check of EOF is needed.

-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages expect depends on:
ii  libc6       2.19-18+deb8u1
ii  libtcl8.6   8.6.2+dfsg-2
ii  tcl-expect  5.45-6

Versions of packages expect recommends:
ii  tcl8.6  8.6.4+dfsg-2
ii  tk8.6   8.6.2-1

expect suggests no packages.

-- no debconf information
Index: expect-5.45/expect.c
===================================================================
--- expect-5.45.orig/expect.c
+++ expect-5.45/expect.c
@@ -1863,7 +1863,11 @@ expRead(
 	/* little, so that from now on it means "no new data arrived */
 	/* but it should be looked at again anyway". */
 	if (cc == 0) {
-	    cc = EXP_EOF;
+	    /* the meaning of 0 from i_read just may mean eof. So, whether */
+	    /* the eof condition really exists must be checked explicitly. */
+	    if (Tcl_Eof(esPtr->channel)) {
+		cc = EXP_EOF;
+	    }
 	} else if (cc > 0) {
 	    /* successfully read data */
 	} else {

Reply via email to