summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2015-11-27 22:19:08 +0800
committerMatt Johnston <matt@ucc.asn.au>2015-11-27 22:19:08 +0800
commita3049d6433ec461113c60181014caa8f7a532db4 (patch)
tree08f3db44fa218a0c26c096d8292f42a7d3c5f8d1
parentee353847be7b98de6d2a989f3522b5bd989261e4 (diff)
Fix "Avoid queueing into circbuffer when the channel is about to close"
which broken handling EAGAIN/EINTR
-rw-r--r--common-channel.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/common-channel.c b/common-channel.c
index 8a10105..40353c2 100644
--- a/common-channel.c
+++ b/common-channel.c
@@ -445,9 +445,10 @@ static int writechannel_fallback(struct Channel* channel, int fd, circbuffer *cb
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 @@ static int writechannel_writev(struct Channel* channel, int fd, circbuffer *cbuf
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 @@ static int writechannel_writev(struct Channel* channel, int fd, circbuffer *cbuf
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 */