diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-01-22 22:58:50 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-01-23 10:44:34 +1100 |
commit | d691588b8e29622c66abf8932362b522cf7f4051 (patch) | |
tree | 38473381f76258ceb0bae3c977b8dcb2b5d2eaee | |
parent | f99ef8de967949a1fc25a5c28263ea32736e5943 (diff) |
upstream: backoff reading messages from active connections when the
input buffer is too full to read one, or if the output buffer is too full to
enqueue a response; feedback & ok dtucker@
OpenBSD-Commit-ID: df3c5b6d57c968975875de40d8955cbfed05a6c8
-rw-r--r-- | ssh-agent.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ssh-agent.c b/ssh-agent.c index 6baebc31..d06ecfd9 100644 --- a/ssh-agent.c +++ b/ssh-agent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-agent.c,v 1.232 2018/11/09 02:57:58 djm Exp $ */ +/* $OpenBSD: ssh-agent.c,v 1.233 2019/01/22 22:58:50 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -96,6 +96,8 @@ /* Maximum accepted message length */ #define AGENT_MAX_LEN (256*1024) +/* Maximum bytes to read from client socket */ +#define AGENT_RBUF_LEN (4096) typedef enum { AUTH_UNUSED, @@ -839,7 +841,7 @@ handle_socket_read(u_int socknum) static int handle_conn_read(u_int socknum) { - char buf[1024]; + char buf[AGENT_RBUF_LEN]; ssize_t len; int r; @@ -946,6 +948,7 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds) struct pollfd *pfd = *pfdp; size_t i, j, npfd = 0; time_t deadline; + int r; /* Count active sockets */ for (i = 0; i < sockets_alloc; i++) { @@ -983,8 +986,19 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds) case AUTH_CONNECTION: pfd[j].fd = sockets[i].fd; pfd[j].revents = 0; - /* XXX backoff when input buffer full */ - pfd[j].events = POLLIN; + /* + * Only prepare to read if we can handle a full-size + * input read buffer and enqueue a max size reply.. + */ + if ((r = sshbuf_check_reserve(sockets[i].input, + AGENT_RBUF_LEN)) == 0 && + (r = sshbuf_check_reserve(sockets[i].output, + AGENT_MAX_LEN)) == 0) + pfd[j].events = POLLIN; + else if (r != SSH_ERR_NO_BUFFER_SPACE) { + fatal("%s: buffer error: %s", + __func__, ssh_err(r)); + } if (sshbuf_len(sockets[i].output) > 0) pfd[j].events |= POLLOUT; j++; |