summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2001-11-25 02:21:46 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2001-11-25 02:21:46 +0000
commit8dc7035fbcb1050bb2f78cd4de06db1478edf637 (patch)
treedaf7b1453e524bad1356012da2f5ac2d83cff25b
parent09dbdbc3d7601bad0208651446f78f1200a96e37 (diff)
Add support to limit the maximum size of the input line (to 128KB which
should be _more_ than enough for any header line. :)
-rw-r--r--src/sock.c12
1 files changed, 11 insertions, 1 deletions
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;