Commit 700f0aff24d9b292f24d802c3af3b5c1705193c5

Carlos Martín Nieto 2015-12-29T13:38:01

Merge pull request #3562 from mgorny/ssh-read-stderr-fail ssh_stream_read(): fix possible *bytes_read < 0 branch

diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index ffa4a24..239e0ba 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;
+		}
 	}