www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: [PATCH] session_startup: manage server data before server identification

[PATCH] session_startup: manage server data before server identification

From: Alfred Gebert <alfred.gebert_at_gmail.com>
Date: Mon, 31 Jan 2011 15:50:27 +0100

Fix the bug that libssh2 could not connect if the sftp server
sends data before sending the version string.

http://tools.ietf.org/html/rfc4253#section-4.2

"The server MAY send other lines of data before sending the version
string. Each line SHOULD be terminated by a Carriage Return and Line
Feed. Such lines MUST NOT begin with "SSH-", and SHOULD be encoded
in ISO-10646 UTF-8 [RFC3629] (language is not specified). Clients
MUST be able to process such lines."

---
 src/session.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
Perhaps a nicer fix is to move the do loop inside banner_receive().
diff --git a/src/session.c b/src/session.c
index 0b05843..c8d21fe 100644
--- a/src/session.c
+++ b/src/session.c
@@ -659,11 +659,15 @@ session_startup(LIBSSH2_SESSION *session,
libssh2_socket_t sock)
     }
     if (session->startup_state == libssh2_NB_state_sent) {
-        rc = banner_receive(session);
-        if (rc) {
-            return _libssh2_error(session, rc,
-                                  "Failed getting banner");
-        }
+        do {
+            session->banner_TxRx_state = libssh2_NB_state_idle;
+
+            rc = banner_receive(session);
+            if (rc) {
+                return _libssh2_error(session, rc,
+                                      "Failed getting banner");
+            }
+        } while( strncmp( "SSH-", session->remote.banner, 4));
         session->startup_state = libssh2_NB_state_sent1;
     }
-- 
1.7.3.1.msysgit.0
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-01-31

the libssh2 team