From 8dc7035fbcb1050bb2f78cd4de06db1478edf637 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Sun, 25 Nov 2001 02:21:46 +0000 Subject: Add support to limit the maximum size of the input line (to 128KB which should be _more_ than enough for any header line. :) --- src/sock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sock.c b/src/sock.c index fbbe748..fe4677d 100644 --- a/src/sock.c +++ b/src/sock.c @@ -1,4 +1,4 @@ -/* $Id: sock.c,v 1.17 2001-11-23 01:18:43 rjkaes Exp $ +/* $Id: sock.c,v 1.18 2001-11-25 02:21:46 rjkaes Exp $ * * Sockets are created and destroyed here. When a new connection comes in from * a client, we need to copy the socket and the create a second socket to the @@ -268,6 +268,7 @@ safe_read(int fd, void *buffer, size_t count) * termination), 0 if the socket was closed, and -1 on all other errors. */ #define SEGMENT_LEN (512) +#define MAXIMUM_BUFFER_LENGTH (128 * 1024) ssize_t readline(int fd, char **whole_buffer) { @@ -305,6 +306,15 @@ readline(int fd, char **whole_buffer) whole_buffer_len += diff; + /* + * Don't allow the buffer to grow without bound. If we + * get to more than MAXIMUM_BUFFER_LENGTH close. + */ + if (whole_buffer_len > MAXIMUM_BUFFER_LENGTH) { + ret = -EOUTRANGE; + goto CLEANUP; + } + line_ptr->data = safemalloc(diff); if (!line_ptr->data) { ret = -ENOMEMORY; -- cgit v1.2.3