4.6p1 chan_read_failed error

Darren Tucker
2007-04-09T09:32:46Z

On Mon, Apr 09, 2007 at 08:46:56AM +1000, Damien Miller
wrote:
> On Wed, 4 Apr 2007, Damien Miller wrote:
>
> > Well, it also undoes the fix for bug #52. I think it is safe to simply
hush
> > the error message:
>
> ugh, the logic in that patch was almost, but not completely, wrong. Please
> try this one instead:

I can reproduce the problem on Solaris 8 but that patch does not resolve
the spurious errors for me (which appears to be because the read is
returning zero).

BTW, While looking at it, though, I was bothered enormously by the
PTY_ZEROREAD ifdef mess which made it hard to read.  I think we should
do something like this once the original problem is sorted out.

Index: Makefile.in
==================================================================RCS file:
/usr/local/src/security/openssh/cvs/openssh/Makefile.in,v
retrieving revision 1.284
diff -u -p -r1.284 Makefile.in
--- Makefile.in	25 Mar 2007 08:26:01 -0000	1.284
+++ Makefile.in	9 Apr 2007 09:01:03 -0000
@@ -71,7 +71,7 @@ LIBSSH_OBJS=acss.o authfd.o authfile.o b
 	atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \
 	monitor_fdpass.o rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o \
 	kexgex.o kexdhc.o kexgexc.o scard.o msg.o progressmeter.o dns.o \
-	entropy.o scard-opensc.o gss-genr.o
+	entropy.o scard-opensc.o gss-genr.o platform.o

 SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
 	sshconnect.o sshconnect1.o sshconnect2.o
@@ -86,7 +86,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passw
 	auth-krb5.o \
 	auth2-gss.o gss-serv.o gss-serv-krb5.o \
 	loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
-	audit.o audit-bsm.o platform.o
+	audit.o audit-bsm.o

 MANPAGES	= scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out
ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out
ssh-rand-helper.8.out ssh-keysign.8.out sshd_config.5.out ssh_config.5.out
 MANPAGES_IN	= scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1
sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 sshd_config.5
ssh_config.5
Index: channels.c
==================================================================RCS file:
/usr/local/src/security/openssh/cvs/openssh/channels.c,v
retrieving revision 1.251
diff -u -p -r1.251 channels.c
--- channels.c	28 Jan 2007 23:16:28 -0000	1.251
+++ channels.c	9 Apr 2007 09:05:35 -0000
@@ -1455,12 +1455,7 @@ channel_handle_rfd(Channel *c, fd_set *r
 		if (len < 0 && (errno == EINTR ||
 		    (errno == EAGAIN && !(c->isatty &&
c->detach_close))))
 			return 1;
-#ifndef PTY_ZEROREAD
-		if (len <= 0) {
-#else
-		if ((!c->isatty && len <= 0) ||
-		    (c->isatty && (len < 0 || (len == 0 && errno !=
0)))) {
-#endif
+		if (platform_rdrw_eof(len, c->isatty, errno)) {
 			debug2("channel %d: read<=0 rfd %d len %d",
 			    c->self, c->rfd, len);
 			if (c->type != SSH_CHANNEL_OPEN) {
Index: platform.c
==================================================================RCS file:
/usr/local/src/security/openssh/cvs/openssh/platform.c,v
retrieving revision 1.1
diff -u -p -r1.1 platform.c
--- platform.c	30 Aug 2006 17:24:41 -0000	1.1
+++ platform.c	9 Apr 2007 09:06:36 -0000
@@ -44,3 +44,15 @@ platform_post_fork_child(void)
 	solaris_contract_post_fork_child();
 #endif
 }
+
+int
+platform_rdrw_eof(size_t len, int is_tty, int errno)
+{
+#ifdef PTY_ZEROREAD
+	if (is_tty && len == 0 && errno == 0)
+		return 0;
+#endif
+	if (len <= 0)
+		return 1;
+	return 0;
+}
Index: platform.h
==================================================================RCS file:
/usr/local/src/security/openssh/cvs/openssh/platform.h,v
retrieving revision 1.1
diff -u -p -r1.1 platform.h
--- platform.h	30 Aug 2006 17:24:41 -0000	1.1
+++ platform.h	9 Apr 2007 09:05:35 -0000
@@ -21,3 +21,4 @@
 void platform_pre_fork(void);
 void platform_post_fork_parent(pid_t child_pid);
 void platform_post_fork_child(void);
+int platform_rdrw_eof(size_t, int, int);
Index: serverloop.c
==================================================================RCS file:
/usr/local/src/security/openssh/cvs/openssh/serverloop.c,v
retrieving revision 1.151
diff -u -p -r1.151 serverloop.c
--- serverloop.c	28 Jan 2007 23:16:28 -0000	1.151
+++ serverloop.c	9 Apr 2007 09:05:35 -0000
@@ -420,12 +420,7 @@ process_input(fd_set *readset)
 		if (len < 0 && (errno == EINTR ||
 		    (errno == EAGAIN && !child_terminated))) {
 			/* do nothing */
-#ifndef PTY_ZEROREAD
-		} else if (len <= 0) {
-#else
-		} else if ((!isatty(fdout) && len <= 0) ||
-		    (isatty(fdout) && (len < 0 || (len == 0 && errno !=
0)))) {
-#endif
+		} else if (platform_rdrw_eof(len, isatty(fderr), errno)) {
 			fdout_eof = 1;
 		} else {
 			buffer_append(&stdout_buffer, buf, len);
@@ -439,12 +434,7 @@ process_input(fd_set *readset)
 		if (len < 0 && (errno == EINTR ||
 		    (errno == EAGAIN && !child_terminated))) {
 			/* do nothing */
-#ifndef PTY_ZEROREAD
-		} else if (len <= 0) {
-#else
-		} else if ((!isatty(fderr) && len <= 0) ||
-		    (isatty(fderr) && (len < 0 || (len == 0 && errno !=
0)))) {
-#endif
+		} else if (platform_rdrw_eof(len, isatty(fderr), errno)) {
 			fderr_eof = 1;
 		} else {
 			buffer_append(&stderr_buffer, buf, len);

--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.