summaryrefslogtreecommitdiffhomepage
path: root/common-session.c
diff options
context:
space:
mode:
Diffstat (limited to 'common-session.c')
-rw-r--r--common-session.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/common-session.c b/common-session.c
index e8dc650..a16d1f9 100644
--- a/common-session.c
+++ b/common-session.c
@@ -143,27 +143,21 @@ void session_loop(void(*loophandler)()) {
dropbear_exit("Terminated by signal");
}
- if (val < 0) {
- if (errno == EINTR) {
- /* This must happen even if we've been interrupted, so that
- * changed signal-handler vars can take effect etc */
- if (loophandler) {
- loophandler();
- }
- continue;
- } else {
- dropbear_exit("Error in select");
- }
+ if (val < 0 && errno != EINTR) {
+ dropbear_exit("Error in select");
+ }
+
+ if (val <= 0) {
+ /* If we were interrupted or the select timed out, we still
+ * want to iterate over channels etc for reading, to handle
+ * server processes exiting etc.
+ * We don't want to read/write FDs. */
+ FD_ZERO(&writefd);
+ FD_ZERO(&readfd);
}
/* check for auth timeout, rekeying required etc */
checktimeouts();
-
- if (val == 0) {
- /* timeout */
- TRACE(("select timeout"))
- continue;
- }
/* process session socket's incoming/outgoing data */
if (ses.sock != -1) {
@@ -229,13 +223,11 @@ void session_identification() {
/* write our version string, this blocks */
if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n",
strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
- dropbear_exit("Error writing ident string");
+ ses.remoteclosed();
}
- /* We allow up to 9 lines before the actual version string, to
- * account for wrappers/cruft etc. According to the spec only the client
- * needs to handle this, but no harm in letting the server handle it too */
- for (i = 0; i < 10; i++) {
+ /* If they send more than 50 lines, something is wrong */
+ for (i = 0; i < 50; i++) {
len = ident_readln(ses.sock, linebuf, sizeof(linebuf));
if (len < 0 && errno != EINTR) {
@@ -252,13 +244,19 @@ void session_identification() {
if (!done) {
TRACE(("err: %s for '%s'\n", strerror(errno), linebuf))
- dropbear_exit("Failed to get remote version");
+ ses.remoteclosed();
} else {
/* linebuf is already null terminated */
ses.remoteident = m_malloc(len);
memcpy(ses.remoteident, linebuf, len);
}
+ /* Shall assume that 2.x will be backwards compatible. */
+ if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
+ && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
+ dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
+ }
+
TRACE(("remoteident: %s", ses.remoteident))
}