Do not allow chain length to expand indefinitely.

svn:r1007
This commit is contained in:
Nick Mathewson 2009-01-14 19:39:17 +00:00
parent ad7f1b4ae9
commit 3552ac1eb3

View File

@ -640,6 +640,8 @@ evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out,
return (line);
}
#define EVBUFFER_CHAIN_MAX_AUTO_SIZE 4096
/* Adds data to an event buffer */
int
@ -680,8 +682,9 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen)
}
/* we need to add another chain */
/* XXX Does this double the length of every successive chain? */
to_alloc = chain->buffer_len << 1;
to_alloc = chain->buffer_len;
if (to_alloc <= EVBUFFER_CHAIN_MAX_AUTO_SIZE/2)
to_alloc <<= 1;
if (datlen > to_alloc)
to_alloc = datlen;
chain->next = evbuffer_chain_new(to_alloc);