View | Details | Raw Unified | Return to bug 896 | Differences between
and this patch

Collapse All | Expand All

(-)buffer.c (-3 / +28 lines)
Lines 18-23 RCSID("$OpenBSD: buffer.c,v 1.22 2004/10 Link Here
18
#include "buffer.h"
18
#include "buffer.h"
19
#include "log.h"
19
#include "log.h"
20
20
21
#define BUFFER_MAX_SIZE		0xa00000
22
#define BUFFER_MAX_APPEND	0x100000
23
#define BUFFER_ALLOC_INCREMENT	32768
24
21
/* Initializes the buffer structure. */
25
/* Initializes the buffer structure. */
22
26
23
void
27
void
Lines 78-84 buffer_append_space(Buffer *buffer, u_in Link Here
78
	u_int newlen;
82
	u_int newlen;
79
	void *p;
83
	void *p;
80
84
81
	if (len > 0x100000)
85
	if (len > BUFFER_MAX_APPEND)
82
		fatal("buffer_append_space: len %u not supported", len);
86
		fatal("buffer_append_space: len %u not supported", len);
83
87
84
	/* If the buffer is empty, start using it from the beginning. */
88
	/* If the buffer is empty, start using it from the beginning. */
Lines 106-113 restart: Link Here
106
	}
110
	}
107
	/* Increase the size of the buffer and retry. */
111
	/* Increase the size of the buffer and retry. */
108
112
109
	newlen = buffer->alloc + len + 32768;
113
	newlen = buffer->alloc + len + BUFFER_ALLOC_INCREMENT;
110
	if (newlen > 0xa00000)
114
	if (newlen > BUFFER_MAX_SIZE)
111
		fatal("buffer_append_space: alloc %u not supported",
115
		fatal("buffer_append_space: alloc %u not supported",
112
		    newlen);
116
		    newlen);
113
	buffer->buf = xrealloc(buffer->buf, newlen);
117
	buffer->buf = xrealloc(buffer->buf, newlen);
Lines 122-127 u_int Link Here
122
buffer_len(Buffer *buffer)
126
buffer_len(Buffer *buffer)
123
{
127
{
124
	return buffer->end - buffer->offset;
128
	return buffer->end - buffer->offset;
129
}
130
131
/*
132
 * Returns the number of bytes that may be safely appended to the buffer in
133
 * one operation.
134
 */
135
136
u_int
137
buffer_max_append(Buffer *buffer)
138
{
139
	long remaining;
140
141
	if (buffer->end > BUFFER_MAX_SIZE)	/* should never happen */
142
		fatal("buffer_max_add: buffer has exceeded allowable size");
143
144
	/* We need to allow for the increment buffer_append_space will add. */
145
	remaining = BUFFER_MAX_SIZE - BUFFER_ALLOC_INCREMENT - buffer->end;
146
147
	if (remaining < 0)
148
		return 0;
149
	return MIN(BUFFER_MAX_APPEND, (u_int)remaining);
125
}
150
}
126
151
127
/* Gets data from the beginning of the buffer. */
152
/* Gets data from the beginning of the buffer. */
(-)buffer.h (+1 lines)
Lines 28-33 void buffer_clear(Buffer *); Link Here
28
void	 buffer_free(Buffer *);
28
void	 buffer_free(Buffer *);
29
29
30
u_int	 buffer_len(Buffer *);
30
u_int	 buffer_len(Buffer *);
31
u_int	 buffer_max_append(Buffer *);
31
void	*buffer_ptr(Buffer *);
32
void	*buffer_ptr(Buffer *);
32
33
33
void	 buffer_append(Buffer *, const void *, u_int);
34
void	 buffer_append(Buffer *, const void *, u_int);
(-)channels.c (-3 / +12 lines)
Lines 56-61 RCSID("$OpenBSD: channels.c,v 1.211 2004 Link Here
56
#include "pathnames.h"
56
#include "pathnames.h"
57
#include "bufaux.h"
57
#include "bufaux.h"
58
58
59
#define CHANNEL_MAX_READ_BUFSZ	(1024 * 16)
60
59
/* -- channel core */
61
/* -- channel core */
60
62
61
/*
63
/*
Lines 711-716 channel_pre_open(Channel *c, fd_set * re Link Here
711
{
713
{
712
	u_int limit = compat20 ? c->remote_window : packet_get_maxsize();
714
	u_int limit = compat20 ? c->remote_window : packet_get_maxsize();
713
715
716
	debug("DAZ: buffer_max_append %u", buffer_max_append(&c->input));
717
	if (buffer_max_append(&c->input) < CHANNEL_MAX_READ_BUFSZ) {
718
		debug2("channel_pre_open: channel %d: input buffer full",
719
		    c->self);
720
		limit = 0;
721
	}
722
714
	if (c->istate == CHAN_INPUT_OPEN &&
723
	if (c->istate == CHAN_INPUT_OPEN &&
715
	    limit > 0 &&
724
	    limit > 0 &&
716
	    buffer_len(&c->input) < limit)
725
	    buffer_len(&c->input) < limit)
Lines 1115-1121 channel_post_x11_listener(Channel *c, fd Link Here
1115
	struct sockaddr addr;
1124
	struct sockaddr addr;
1116
	int newsock;
1125
	int newsock;
1117
	socklen_t addrlen;
1126
	socklen_t addrlen;
1118
	char buf[16384], *remote_ipaddr;
1127
	char buf[CHANNEL_MAX_READ_BUFSZ], *remote_ipaddr;
1119
	int remote_port;
1128
	int remote_port;
1120
1129
1121
	if (FD_ISSET(c->sock, readset)) {
1130
	if (FD_ISSET(c->sock, readset)) {
Lines 1359-1365 channel_post_connecting(Channel *c, fd_s Link Here
1359
static int
1368
static int
1360
channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset)
1369
channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset)
1361
{
1370
{
1362
	char buf[16*1024];
1371
	char buf[CHANNEL_MAX_READ_BUFSZ];
1363
	int len;
1372
	int len;
1364
1373
1365
	if (c->rfd != -1 &&
1374
	if (c->rfd != -1 &&
Lines 1448-1454 channel_handle_wfd(Channel *c, fd_set * Link Here
1448
static int
1457
static int
1449
channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset)
1458
channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset)
1450
{
1459
{
1451
	char buf[16*1024];
1460
	char buf[CHANNEL_MAX_READ_BUFSZ];
1452
	int len;
1461
	int len;
1453
1462
1454
/** XXX handle drain efd, too */
1463
/** XXX handle drain efd, too */

Return to bug 896