summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-12-26 17:17:05 +0100
committerMichał Górny <mgorny@gentoo.org>2015-12-26 17:17:05 +0100
commit02fdc2db225b1ca21aab2000ba4a873f335d6707 (patch)
tree23dfa1f71ce7032ed15a16938d1e384f896406e7
parent3d29b12c9c8ba3272bbc5523fccde96c06ee6b83 (diff)
downloadlibgit2-02fdc2db225b1ca21aab2000ba4a873f335d6707.tar.gz
ssh_stream_read(): fix possible *bytes_read < 0 branch
Fix the possibility of returning successfully from ssh_stream_read() with *bytes_read < 0. This would occur if stdout channel read resulted in 0, and stderr channel read failed afterwards.
-rw-r--r--src/transports/ssh.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index ffa4a24a7..239e0bae7 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -136,9 +136,14 @@ static int ssh_stream_read(
* not-found error, so read from stderr and signal EOF on
* stderr.
*/
- if (rc == 0 && (rc = libssh2_channel_read_stderr(s->channel, buffer, buf_size)) > 0) {
- giterr_set(GITERR_SSH, "%*s", rc, buffer);
- return GIT_EEOF;
+ if (rc == 0) {
+ if ((rc = libssh2_channel_read_stderr(s->channel, buffer, buf_size)) > 0) {
+ giterr_set(GITERR_SSH, "%*s", rc, buffer);
+ return GIT_EEOF;
+ } else if (rc < LIBSSH2_ERROR_NONE) {
+ ssh_error(s->session, "SSH could not read stderr");
+ return -1;
+ }
}