bug & patch in ServerAliveInterval (openssh 4.3-p2)

Darren Tucker dtucker at zip.com.au
Sat May 6 15:10:26 EST 2006


Hi All.

Markus pointed out that the same problem applies to sshd and that the
earlier change when applied to sshd could still be fooled under some
conditions.

Below is a slightly different method that seems to work OK for both
client and server.

Index: clientloop.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/clientloop.c,v
retrieving revision 1.162
diff -u -p -r1.162 clientloop.c
--- clientloop.c	2006/04/20 09:27:09	1.162
+++ clientloop.c	2006/05/06 05:05:47
@@ -466,6 +466,8 @@ client_wait_until_can_do_something(fd_se
     int *maxfdp, u_int *nallocp, int rekeying)
 {
 	struct timeval tv, *tvp;
+	static time_t lastalive;
+	time_t now;
 	int ret;
 
 	/* Add any selections by the channel mechanism. */
@@ -540,8 +542,15 @@ client_wait_until_can_do_something(fd_se
 		snprintf(buf, sizeof buf, "select: %s\r\n", strerror(errno));
 		buffer_append(&stderr_buffer, buf, strlen(buf));
 		quit_pending = 1;
-	} else if (ret == 0)
-		server_alive_check();
+	} else if (compat20 && options.server_alive_interval) {
+		now = time(NULL);
+		if (lastalive == 0 || FD_ISSET(connection_in, *readsetp)) {
+			lastalive = now;
+		} else if (lastalive + options.server_alive_interval <= now) {
+			lastalive = now;
+			server_alive_check();
+		}
+	}
 }
 
 static void
Index: serverloop.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/serverloop.c,v
retrieving revision 1.135
diff -u -p -r1.135 serverloop.c
--- serverloop.c	2006/03/25 18:30:55	1.135
+++ serverloop.c	2006/05/06 05:05:47
@@ -258,6 +258,8 @@ wait_until_can_do_something(fd_set **rea
     u_int *nallocp, u_int max_time_milliseconds)
 {
 	struct timeval tv, *tvp;
+	static time_t lastalive;
+	time_t now;
 	int ret;
 	int client_alive_scheduled = 0;
 
@@ -342,8 +344,15 @@ wait_until_can_do_something(fd_set **rea
 		memset(*writesetp, 0, *nallocp);
 		if (errno != EINTR)
 			error("select: %.100s", strerror(errno));
-	} else if (ret == 0 && client_alive_scheduled)
-		client_alive_check();
+	} else if (compat20 && options.client_alive_interval) {
+		now = time(NULL);
+		if (lastalive == 0 || FD_ISSET(connection_in, *readsetp)) {
+			lastalive = now;
+		} else if (lastalive + options.client_alive_interval <= now) {
+			lastalive = now;
+			client_alive_check();
+		}
+	}
 
 	notify_done(*readsetp);
 }

-- 
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.




More information about the openssh-unix-dev mailing list