summaryrefslogtreecommitdiff
path: root/ssh-agent.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-agent.c')
-rw-r--r--ssh-agent.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/ssh-agent.c b/ssh-agent.c
index d8a8260f9..d06ecfd98 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-agent.c,v 1.231 2018/05/11 03:38:51 djm Exp $ */ 1/* $OpenBSD: ssh-agent.c,v 1.233 2019/01/22 22:58:50 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -96,6 +96,8 @@
96 96
97/* Maximum accepted message length */ 97/* Maximum accepted message length */
98#define AGENT_MAX_LEN (256*1024) 98#define AGENT_MAX_LEN (256*1024)
99/* Maximum bytes to read from client socket */
100#define AGENT_RBUF_LEN (4096)
99 101
100typedef enum { 102typedef enum {
101 AUTH_UNUSED, 103 AUTH_UNUSED,
@@ -839,7 +841,7 @@ handle_socket_read(u_int socknum)
839static int 841static int
840handle_conn_read(u_int socknum) 842handle_conn_read(u_int socknum)
841{ 843{
842 char buf[1024]; 844 char buf[AGENT_RBUF_LEN];
843 ssize_t len; 845 ssize_t len;
844 int r; 846 int r;
845 847
@@ -946,6 +948,7 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds)
946 struct pollfd *pfd = *pfdp; 948 struct pollfd *pfd = *pfdp;
947 size_t i, j, npfd = 0; 949 size_t i, j, npfd = 0;
948 time_t deadline; 950 time_t deadline;
951 int r;
949 952
950 /* Count active sockets */ 953 /* Count active sockets */
951 for (i = 0; i < sockets_alloc; i++) { 954 for (i = 0; i < sockets_alloc; i++) {
@@ -983,8 +986,19 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds)
983 case AUTH_CONNECTION: 986 case AUTH_CONNECTION:
984 pfd[j].fd = sockets[i].fd; 987 pfd[j].fd = sockets[i].fd;
985 pfd[j].revents = 0; 988 pfd[j].revents = 0;
986 /* XXX backoff when input buffer full */ 989 /*
987 pfd[j].events = POLLIN; 990 * Only prepare to read if we can handle a full-size
991 * input read buffer and enqueue a max size reply..
992 */
993 if ((r = sshbuf_check_reserve(sockets[i].input,
994 AGENT_RBUF_LEN)) == 0 &&
995 (r = sshbuf_check_reserve(sockets[i].output,
996 AGENT_MAX_LEN)) == 0)
997 pfd[j].events = POLLIN;
998 else if (r != SSH_ERR_NO_BUFFER_SPACE) {
999 fatal("%s: buffer error: %s",
1000 __func__, ssh_err(r));
1001 }
988 if (sshbuf_len(sockets[i].output) > 0) 1002 if (sshbuf_len(sockets[i].output) > 0)
989 pfd[j].events |= POLLOUT; 1003 pfd[j].events |= POLLOUT;
990 j++; 1004 j++;
@@ -1095,10 +1109,6 @@ main(int ac, char **av)
1095 if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) 1109 if (getrlimit(RLIMIT_NOFILE, &rlim) == -1)
1096 fatal("%s: getrlimit: %s", __progname, strerror(errno)); 1110 fatal("%s: getrlimit: %s", __progname, strerror(errno));
1097 1111
1098#ifdef WITH_OPENSSL
1099 OpenSSL_add_all_algorithms();
1100#endif
1101
1102 __progname = ssh_get_progname(av[0]); 1112 __progname = ssh_get_progname(av[0]);
1103 seed_rng(); 1113 seed_rng();
1104 1114
@@ -1199,7 +1209,7 @@ main(int ac, char **av)
1199 */ 1209 */
1200#define SSH_AGENT_MIN_FDS (3+1+1+1+4) 1210#define SSH_AGENT_MIN_FDS (3+1+1+1+4)
1201 if (rlim.rlim_cur < SSH_AGENT_MIN_FDS) 1211 if (rlim.rlim_cur < SSH_AGENT_MIN_FDS)
1202 fatal("%s: file descriptior rlimit %lld too low (minimum %u)", 1212 fatal("%s: file descriptor rlimit %lld too low (minimum %u)",
1203 __progname, (long long)rlim.rlim_cur, SSH_AGENT_MIN_FDS); 1213 __progname, (long long)rlim.rlim_cur, SSH_AGENT_MIN_FDS);
1204 maxfds = rlim.rlim_cur - SSH_AGENT_MIN_FDS; 1214 maxfds = rlim.rlim_cur - SSH_AGENT_MIN_FDS;
1205 1215