diff options
author | 2019-01-22 22:58:50 +0000 | |
---|---|---|
committer | 2019-01-22 22:58:50 +0000 | |
commit | 6c1d2b3a0bee9027396339c9757b8b23e8ba1b69 (patch) | |
tree | 48931c09492ea8d2d3b4fc692707a2369e138ae9 /usr.bin/ssh/ssh-agent.c | |
parent | The kernel interpreted bogus lengths in RPC calls during NFS boot. (diff) | |
download | wireguard-openbsd-6c1d2b3a0bee9027396339c9757b8b23e8ba1b69.tar.xz wireguard-openbsd-6c1d2b3a0bee9027396339c9757b8b23e8ba1b69.zip |
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@
Diffstat (limited to 'usr.bin/ssh/ssh-agent.c')
-rw-r--r-- | usr.bin/ssh/ssh-agent.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/usr.bin/ssh/ssh-agent.c b/usr.bin/ssh/ssh-agent.c index 59ee90cbfa8..7ff32ebb179 100644 --- a/usr.bin/ssh/ssh-agent.c +++ b/usr.bin/ssh/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 @@ -81,6 +81,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, @@ -824,7 +826,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; @@ -931,6 +933,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++) { @@ -968,8 +971,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++; |