]> andersk Git - openssh.git/blobdiff - ssh-agent.c
- djm@cvs.openbsd.org 2010/01/30 02:54:53
[openssh.git] / ssh-agent.c
index 1a54a27847c3d1be7cda7884cff9112b06e7b120..df3a87d9a53021252a4856f0834ab05438805e04 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-agent.c,v 1.160 2009/03/23 08:31:19 tobias Exp $ */
+/* $OpenBSD: ssh-agent.c,v 1.162 2009/09/01 14:43:17 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -919,11 +919,11 @@ after_select(fd_set *readset, fd_set *writeset)
        socklen_t slen;
        char buf[1024];
        int len, sock;
-       u_int i;
+       u_int i, orig_alloc;
        uid_t euid;
        gid_t egid;
 
-       for (i = 0; i < sockets_alloc; i++)
+       for (i = 0, orig_alloc = sockets_alloc; i < orig_alloc; i++)
                switch (sockets[i].type) {
                case AUTH_UNUSED:
                        break;
@@ -956,16 +956,13 @@ after_select(fd_set *readset, fd_set *writeset)
                case AUTH_CONNECTION:
                        if (buffer_len(&sockets[i].output) > 0 &&
                            FD_ISSET(sockets[i].fd, writeset)) {
-                               do {
-                                       len = write(sockets[i].fd,
-                                           buffer_ptr(&sockets[i].output),
-                                           buffer_len(&sockets[i].output));
-                                       if (len == -1 && (errno == EAGAIN ||
-                                           errno == EINTR ||
-                                           errno == EWOULDBLOCK))
-                                               continue;
-                                       break;
-                               } while (1);
+                               len = write(sockets[i].fd,
+                                   buffer_ptr(&sockets[i].output),
+                                   buffer_len(&sockets[i].output));
+                               if (len == -1 && (errno == EAGAIN ||
+                                   errno == EWOULDBLOCK ||
+                                   errno == EINTR))
+                                       continue;
                                if (len <= 0) {
                                        close_socket(&sockets[i]);
                                        break;
@@ -973,14 +970,11 @@ after_select(fd_set *readset, fd_set *writeset)
                                buffer_consume(&sockets[i].output, len);
                        }
                        if (FD_ISSET(sockets[i].fd, readset)) {
-                               do {
-                                       len = read(sockets[i].fd, buf, sizeof(buf));
-                                       if (len == -1 && (errno == EAGAIN ||
-                                           errno == EINTR ||
-                                           errno == EWOULDBLOCK))
-                                               continue;
-                                       break;
-                               } while (1);
+                               len = read(sockets[i].fd, buf, sizeof(buf));
+                               if (len == -1 && (errno == EAGAIN ||
+                                   errno == EWOULDBLOCK ||
+                                   errno == EINTR))
+                                       continue;
                                if (len <= 0) {
                                        close_socket(&sockets[i]);
                                        break;
@@ -1061,6 +1055,7 @@ main(int ac, char **av)
        pid_t pid;
        char pidstrbuf[1 + 3 * sizeof pid];
        struct timeval *tvp = NULL;
+       size_t len;
 
        /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
        sanitise_stdfd();
@@ -1121,8 +1116,8 @@ main(int ac, char **av)
 
        if (ac == 0 && !c_flag && !s_flag) {
                shell = getenv("SHELL");
-               if (shell != NULL &&
-                   strncmp(shell + MAX(strlen(shell) - 3, 0), "csh", 3) == 0)
+               if (shell != NULL && (len = strlen(shell)) > 2 &&
+                   strncmp(shell + len - 3, "csh", 3) == 0)
                        c_flag = 1;
        }
        if (k_flag) {
This page took 0.092934 seconds and 4 git commands to generate.