summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ychat/src/glob.h2
-rw-r--r--ychat/src/sock/sock.cpp19
2 files changed, 16 insertions, 5 deletions
diff --git a/ychat/src/glob.h b/ychat/src/glob.h
index 9e3d6c7..7309196 100644
--- a/ychat/src/glob.h
+++ b/ychat/src/glob.h
@@ -82,7 +82,7 @@
#define POSTBUF 1024
#define READBUF 2048
-#define READSOCK 2048
+#define READSOCK 16384
#define SERVMSG
//#define CTCSEGV
#define VERBOSE
diff --git a/ychat/src/sock/sock.cpp b/ychat/src/sock/sock.cpp
index b145f6b..9202902 100644
--- a/ychat/src/sock/sock.cpp
+++ b/ychat/src/sock/sock.cpp
@@ -311,8 +311,13 @@ sock::handle_client_read(int i_fd, short event, void *p_arg)
if (i_hdr_end == string::npos)
{
- // Headers not fully received yet; wait for more.
- event_add(p_context->p_event, NULL);
+ // Headers not fully received yet. Guard against oversized header
+ // floods: if the buffer is already full with no header terminator, the
+ // request can never be completed - drop it (no re-arm) rather than spin.
+ // The fd leaks for that one abusive request (see the body branch below);
+ // preferable to a crash/spin.
+ if ( p_context->i_buf_len < READSOCK )
+ event_add(p_context->p_event, NULL);
return;
}
@@ -326,8 +331,14 @@ sock::handle_client_read(int i_fd, short event, void *p_arg)
int i_have = (int)s_buf.size() - (int)i_body_off;
if (i_have < i_content_len)
{
- // Body still incomplete; wait for the rest.
- event_add(p_context->p_event, NULL);
+ // Body still incomplete. If the buffer is already full the body
+ // can never fit (oversized POST): drop the request without re-arming
+ // (re-arming a full buffer would spin, and deleting the context
+ // inside this read callback corrupts libevent). The fd leaks for
+ // that one abusive request — acceptable for a toy chat and far
+ // better than a crash/spin. Otherwise wait for the rest.
+ if ( p_context->i_buf_len < READSOCK )
+ event_add(p_context->p_event, NULL);
return;
}
}