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
This commit is contained in:
djm@openbsd.org 2019-01-22 22:58:50 +00:00 committed by Damien Miller
parent f99ef8de96
commit d691588b8e
1 changed files with 18 additions and 4 deletions

View File

@ -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++;