openssh-5.9p1-xauthlocalhostname.diff
[platform/upstream/openssh.git] / serverloop.c
index e224bd0..2f8e3a0 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: serverloop.c,v 1.164 2012/12/07 01:51:35 dtucker Exp $ */
+/* $OpenBSD: serverloop.c,v 1.170 2014/02/02 03:44:31 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -148,7 +148,7 @@ static void
 notify_parent(void)
 {
        if (notify_pipe[1] != -1)
-               write(notify_pipe[1], "", 1);
+               (void)write(notify_pipe[1], "", 1);
 }
 static void
 notify_prepare(fd_set *readset)
@@ -277,7 +277,7 @@ client_alive_check(void)
  */
 static void
 wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
-    u_int *nallocp, u_int max_time_milliseconds)
+    u_int *nallocp, u_int64_t max_time_milliseconds)
 {
        struct timeval tv, *tvp;
        int ret;
@@ -304,7 +304,8 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
        if (compat20 &&
            max_time_milliseconds == 0 && options.client_alive_interval) {
                client_alive_scheduled = 1;
-               max_time_milliseconds = options.client_alive_interval * 1000;
+               max_time_milliseconds =
+                   (u_int64_t)options.client_alive_interval * 1000;
        }
 
        if (compat20) {
@@ -563,7 +564,7 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
        int wait_status;        /* Status returned by wait(). */
        pid_t wait_pid;         /* pid returned by wait(). */
        int waiting_termination = 0;    /* Have displayed waiting close message. */
-       u_int max_time_milliseconds;
+       u_int64_t max_time_milliseconds;
        u_int previous_stdout_buffer_bytes;
        u_int stdout_buffer_bytes;
        int type;
@@ -694,7 +695,7 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
                                /* Display list of open channels. */
                                cp = channel_open_message();
                                buffer_append(&stderr_buffer, cp, strlen(cp));
-                               xfree(cp);
+                               free(cp);
                        }
                }
                max_fd = MAX(connection_in, connection_out);
@@ -722,10 +723,8 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
                /* Process output to the client and to program stdin. */
                process_output(writeset);
        }
-       if (readset)
-               xfree(readset);
-       if (writeset)
-               xfree(writeset);
+       free(readset);
+       free(writeset);
 
        /* Cleanup and termination code. */
 
@@ -825,7 +824,9 @@ void
 server_loop2(Authctxt *authctxt)
 {
        fd_set *readset = NULL, *writeset = NULL;
-       int rekeying = 0, max_fd, nalloc = 0;
+       int rekeying = 0, max_fd;
+       u_int nalloc = 0;
+       u_int64_t rekey_timeout_ms = 0;
 
        debug("Entering interactive session for SSH2.");
 
@@ -854,8 +855,13 @@ server_loop2(Authctxt *authctxt)
 
                if (!rekeying && packet_not_very_much_data_to_write())
                        channel_output_poll();
+               if (options.rekey_interval > 0 && compat20 && !rekeying)
+                       rekey_timeout_ms = packet_get_rekey_timeout() * 1000;
+               else
+                       rekey_timeout_ms = 0;
+
                wait_until_can_do_something(&readset, &writeset, &max_fd,
-                   &nalloc, 0);
+                   &nalloc, rekey_timeout_ms);
 
                if (received_sigterm) {
                        logit("Exiting on signal %d", (int)received_sigterm);
@@ -879,10 +885,8 @@ server_loop2(Authctxt *authctxt)
        }
        collect_children();
 
-       if (readset)
-               xfree(readset);
-       if (writeset)
-               xfree(writeset);
+       free(readset);
+       free(writeset);
 
        /* free all channels, no more reads and writes */
        channel_free_all();
@@ -916,8 +920,8 @@ server_input_stdin_data(int type, u_int32_t seq, void *ctxt)
        data = packet_get_string(&data_len);
        packet_check_eom();
        buffer_append(&stdin_buffer, data, data_len);
-       memset(data, 0, data_len);
-       xfree(data);
+       explicit_bzero(data, data_len);
+       free(data);
 }
 
 static void
@@ -974,8 +978,8 @@ server_request_direct_tcpip(void)
                    originator, originator_port, target, target_port);
        }
 
-       xfree(originator);
-       xfree(target);
+       free(originator);
+       free(target);
 
        return c;
 }
@@ -1104,7 +1108,7 @@ server_input_channel_open(int type, u_int32_t seq, void *ctxt)
                }
                packet_send();
        }
-       xfree(ctype);
+       free(ctype);
 }
 
 static void
@@ -1149,7 +1153,7 @@ server_input_global_request(int type, u_int32_t seq, void *ctxt)
                            listen_address, listen_port,
                            &allocated_listen_port, options.gateway_ports);
                }
-               xfree(listen_address);
+               free(listen_address);
        } else if (strcmp(rtype, "cancel-tcpip-forward") == 0) {
                char *cancel_address;
                u_short cancel_port;
@@ -1161,7 +1165,7 @@ server_input_global_request(int type, u_int32_t seq, void *ctxt)
 
                success = channel_cancel_rport_listener(cancel_address,
                    cancel_port);
-               xfree(cancel_address);
+               free(cancel_address);
        } else if (strcmp(rtype, "no-more-sessions@openssh.com") == 0) {
                no_more_sessions = 1;
                success = 1;
@@ -1174,7 +1178,7 @@ server_input_global_request(int type, u_int32_t seq, void *ctxt)
                packet_send();
                packet_write_wait();
        }
-       xfree(rtype);
+       free(rtype);
 }
 
 static void
@@ -1206,7 +1210,7 @@ server_input_channel_req(int type, u_int32_t seq, void *ctxt)
                packet_put_int(c->remote_id);
                packet_send();
        }
-       xfree(rtype);
+       free(rtype);
 }
 
 static void