changeset 1192:af940cefdba1

Fix "Avoid queueing into circbuffer when the channel is about to close" which broken handling EAGAIN/EINTR
author Matt Johnston <matt@ucc.asn.au>
date Fri, 27 Nov 2015 22:19:08 +0800
parents b370b4b172d0
children da1ed4fcdc4a 089b8e91472b
files common-channel.c
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/common-channel.c	Fri Nov 27 21:26:43 2015 +0800
+++ b/common-channel.c	Fri Nov 27 22:19:08 2015 +0800
@@ -445,9 +445,10 @@
 			close_chan_fd(channel, fd, SHUT_WR);
 			return DROPBEAR_FAILURE;
 		}
+	} else {
+		cbuf_incrread(cbuf, written);
+		channel->recvdonelen += written;
 	}
-	cbuf_incrread(cbuf, written);
-	channel->recvdonelen += written;
 	return DROPBEAR_SUCCESS;
 }
 #endif /* !HAVE_WRITEV */
@@ -460,7 +461,7 @@
 	unsigned char *circ_p1, *circ_p2;
 	unsigned int circ_len1, circ_len2;
 	int io_count = 0;
-	int cbuf_written;
+
 	ssize_t written;
 
 	cbuf_readptrs(cbuf, &circ_p1, &circ_len1, &circ_p2, &circ_len2);
@@ -508,14 +509,14 @@
 			close_chan_fd(channel, fd, SHUT_WR);
 			return DROPBEAR_FAILURE;
 		}
-	} 
-
-	cbuf_written = MIN(circ_len1+circ_len2, (unsigned int)written);
-	cbuf_incrread(cbuf, cbuf_written);
-	if (morelen) {
-		*morelen = written - cbuf_written;
+	} else {
+		int cbuf_written = MIN(circ_len1+circ_len2, (unsigned int)written);
+		cbuf_incrread(cbuf, cbuf_written);
+		if (morelen) {
+			*morelen = written - cbuf_written;
+		}
+		channel->recvdonelen += written;
 	}
-	channel->recvdonelen += written;
 	return DROPBEAR_SUCCESS;
 }
 #endif /* HAVE_WRITEV */